[EMAIL PROTECTED] wrote:
>>    newlist = [ None ] * len(mylist)
>>    for i in range(len(mylist)):
>>       newlist.append(int(e[0]))
> 
> Note that this appends after the Nones, not over them. And note that
> here the name 'e' is undefined.

   What an idiot I am.. Yes, I know that.. And I actually *had* working
code laying around, but rather than opening it and copy-and-pasting, I
simply rewrote it. I obviously meant:

   newlist[i] = int(e[0])

> The most used idiom for that is:
> 
> newlist = [int(e[0]) for e in mylist]

> Or better lazily if you want to create a set, avoiding the list
> creation:
> 
> newlist = set(int(e[0]) for e in mylist)

   ...completely avoiding the design issue I raised altogether. Thanks!
Exactly what I was hoping for! :-)

-- 
Kind regards,
Jan Danielsson
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to