Help doing it the "python way"

Nobody nobody at nowhere.com
Sat May 26 14:02:20 EDT 2012


On Thu, 24 May 2012 13:22:43 -0700, Scott Siegler wrote:

> is there a way to do something like:
> [(x,y-1), (x,y+1) for zzz in coord_list]
> or something along those lines?

	[(xx,yy) for x, y in coord_list for xx, yy in [(x,y-1),(x,y+1)]]
or:
	[(x,yy) for x, y in coord_list for yy in [y-1,y+1]]

Not to be confused with:

	[[(xx,yy) for xx, yy in [(x,y-1),(x,y+1)]] for x, y in coord_list]
or:
	[[(x,yy) for yy in (y-1,y+1)] for x, y in coord_list]

which will produce the same pairs in the same order but as a list
of lists rather than as a single flat list.




More information about the Python-list mailing list