Re: Preallocate? -- potentially brain dead question about performance

2007-02-27 Thread bearophileHUGS
Jan Danielsson: ...completely avoiding the design issue I raised altogether. Thanks! Exactly what I was hoping for! :-) Another common way to do it, it may be a little slower because that n,txt is a tuple: items = set(int(n) for n,txt in mylist) Bye, bearophile --

Preallocate? -- potentially brain dead question about performance

2007-02-26 Thread Jan Danielsson
Hello all, I have a list which contains a bunch of tuples: mylist = [ ('1', 'Foobar'), ('32', 'Baz'), ('4', 'Snorklings') ] (The list can potentially be shorter, or much longer). Now I want to take the first element in each tuple and store it in a list (to use in a Set later on).

Re: Preallocate? -- potentially brain dead question about performance

2007-02-26 Thread bearophileHUGS
Jan Danielsson: 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. The most used idiom for that is: newlist = [int(e[0]) for e in mylist] Or

Re: Preallocate? -- potentially brain dead question about performance

2007-02-26 Thread Jan Danielsson
[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*