On 5/24/2012 2:30 PM Paul Rubin said...
Paul Rubin<no.email@nospam.invalid> writes:
new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list )
Sorry:
new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list))
>>> from itertools import chain
>>> coord_list = zip(range(20,30),range(30,40))
>>> a = [((x,y-1),(x,y+1)) for x,y in coord_list]
>>> b = list(chain(((x,y-1),(x,y+1)) for x,y in coord_list))
>>> a == b
True
>>>
So, why use chain? Is it a premature optimization? Similar to the
practice of using "".join(targets) vs targeta+targetb+...+targetn?
Emile
--
http://mail.python.org/mailman/listinfo/python-list