Re: [Tutor] append question

2009-07-06 Thread Kent Johnson
> 2009/7/6 Steven Buck : >> # I call my data set the psid (Panel Study of Income Dynamics) >> # In Stata this would look like and NXK matrix (N observations and K >> variables) >> psid=Reader(file('data3.dta')) >> >> # I gather this next just creates a list of the variable names. >> varnames=[x.na

Re: [Tutor] append question

2009-07-06 Thread Steven Buck
Thanks for the previous responses. This isn't homework--I'm beyond coursework, although I am a newbie to Python (and I've never had to do much real programming since I've just used Stata for econometric analysis). I'm testing Python as a more powerful alternative to Stata. I've learned from the

Re: [Tutor] append question

2009-07-05 Thread Rich Lovely
2009/7/6 Steven Buck : > Thanks for the previous responses.  This isn't homework--I'm beyond > coursework, although I am a newbie to Python (and I've never had to do much > real programming since I've just used Stata for econometric analysis).  I'm > testing Python as a more powerful alternative to

Re: [Tutor] append question

2009-07-05 Thread Robert Berman
In [1]: test=[[1,2,3],[4,5,6],[7,8,9]] In [3]: testvar2 = [] In [16]: for i in range(len(test)): : testvar2.append(test[i][1]) : : In [17]: testvar2 Out[17]: [2, 5, 8] Robert On Sun, 2009-07-05 at 15:57 -0700, Steven Buck wrote: > Hi Python Tutors: > > I ha

Re: [Tutor] append question

2009-07-05 Thread Rich Lovely
2009/7/5 Steven Buck : for i in len(test): >     testvar2.append(test[i][2]) > > I want testvar2 = [2,5,8] but instead I get the following error message: > > Traceback (most recent call last): >   File "", line 1, in >     for i in len(test): > TypeError: 'int' object is not iterable

Re: [Tutor] append question

2009-07-05 Thread Luke Paireepinart
Read your error message... It highlighted the first line of your for loop ansd said ints aren't iterable. len(list) returns an integer. You want a list of items... for i in range(len(list)): On 7/5/09, Steven Buck wrote: > Hi Python Tutors: > > I have a data structure that looks like: > test

[Tutor] append question

2009-07-05 Thread Steven Buck
Hi Python Tutors: I have a data structure that looks like: >>> test=[[1,2,3],[4,5,6],[7,8,9]] I want to define a new variable that captures the second element of each sublist from above: >>> testvar2 = [] Next I try to capture the aforementioned elements: >>> for i in len(test): t