Re: [Tutor] packing a list of lists

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 10:28 AM, kevin parks wrote: > Interestingly changing: >                out_list.append(ll) > > to > >                out_list.append(list(ll)) > > > seems to work. The part of my brain that understood why that is must have > sleeping. Because it makes a new list instead of

Re: [Tutor] packing a list of lists

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 11:20 AM, vince spicer wrote: > Or even cleaner with list comprehension > > def pack(foo): >     return [x for x in enumerate(foo, 1)] Or just list(enumerate(foo, 1)) For Python 2.5 use [ [i+1, x] for i, x in enumerate(foo) ] Kent

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
On Aug 29, 2009, at 12:23 AM, Michael M Mason wrote: i wrote: def pack(in_seq): out_list=[] x = 1 ll=[1, 1] for each in in_seq: ll[0] = x ll[1] = each out_list.append(ll) #print ll x

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
Interestingly changing: out_list.append(ll) to out_list.append(list(ll)) seems to work. The part of my brain that understood why that is must have sleeping. -k On Aug 28, 2009, at 11:05 PM, i wrote: Back to python after a long long layoff. So i am running

Re: [Tutor] packing a list of lists

2009-08-28 Thread Dave Angel
kevin parks wrote: Back to python after a long long layoff. So i am running into some beginner's confusion... I am trying to plot a list of numbers in gnuplot.py. To do that I am trying to pack the list with an index by iterating over the list so i can get something like: foo = [12, 11, 9,

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
:21 AM, afit...@gmail.com wrote: Enumerate() is returning a tuple, I haven't tested this code but try: [[x[0],x[1]] for x in enumerate(blah,1)] --Original Message-- Sender: tutor-bounces+afith13+python=gmail@python.org To: tutor@python.org Subject: Re: [Tutor] packing a list of

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 10:49 AM, kevin parks wrote: > > Thanks for the replies. Though the list comprehension does not work: > > TypeError: enumerate() takes exactly 1 argument (2 given) > > > On Aug 29, 2009, at 12:20 AM, vince spicer wrote: > > >> >> #print foohough I didn't test your co

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
Thanks for the replies. Though the list comprehension does not work: TypeError: enumerate() takes exactly 1 argument (2 given) On Aug 29, 2009, at 12:20 AM, vince spicer wrote: #print foohough I didn't test your code, I think what you are trying to accomplish can be done using enu

Re: [Tutor] packing a list of lists

2009-08-28 Thread Michael M Mason
Kevin Parks wrote: > def pack(in_seq): > out_list=[] > x = 1 > ll=[1, 1] > for each in in_seq: > ll[0] = x > ll[1] = each > out_list.append(ll) > #print ll > x = x + 1 > print out_list Variable out

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 9:18 AM, vince spicer wrote: > > > On Fri, Aug 28, 2009 at 8:05 AM, kevin parks wrote: > >> Back to python after a long long layoff. So i am running into some >> beginner's confusion... >> >> I am trying to plot a list of numbers in gnuplot.py. To do that I am >> trying t

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 8:05 AM, kevin parks wrote: > Back to python after a long long layoff. So i am running into some > beginner's confusion... > > I am trying to plot a list of numbers in gnuplot.py. To do that I am trying > to pack the list with an index by iterating over the list so i can g