Help doing it the "python way"
Emile van Sebille
emile at fenx.com
Thu May 24 19:12:34 EDT 2012
On 5/24/2012 2:30 PM Paul Rubin said...
> Paul Rubin<no.email at 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
More information about the Python-list
mailing list