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
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
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
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
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,
: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
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
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
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
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
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
11 matches
Mail list logo