[Python Wpg] Sort a list of tuples!
Mark Jenkins
umjenki5 at cc.umanitoba.ca
Mon Apr 24 13:18:09 EDT 2006
> Also Note that almost everywhere one sees "for i in range(len(foo)):"
> one can replace it with "for item in foo:"
Avoiding random access (list[#]) might make a big performance difference
too, I read that lists in emacs lisp are implemented as linked lists,
which made me wonder how python lists are implemented. Does anyone know?
(or have the time to find out?)
This reminds me of a related question, is there a nice pythonish way to
iterate through too equally sized lists in parallel?
# if it turns out that python lists are linked lists,
# this example would be really bad performance wise in
# big lists
for i, value in enumerate(list1):
#do stuff to value and list2[i]
# an alternative
def two_iter_generator( iter1, iter2):
iter1 = iter(iter1)
iter2 = iter(iter2)
try:
while True:
yield (iter1.next(), iter2.next() )
except StopIteration: pass
for value1, value2 in two_iter_generator( range(10), range(10) ):
# do stuff to value1 and value2
More information about the Winnipeg
mailing list