[Tutor] Another list comprehension question
Smith, Jeff
jsmith at medplus.com
Mon Feb 26 21:30:12 CET 2007
I'm probably missing something simple here but is there anyway to
accomplish the following with a list comprehension?
def get_clists():
return [1, 2, 3]
def get_clist(num):
if num == 1:
return ['a', 'b', 'c']
if num == 2:
return ['x', 'y', 'z']
if num == 3:
return ['p', 'q']
files = list()
for clist in get_clists():
files += get_clist(clist)
My first attempt was to try
[get_clist(c) for c in get_clists()]
but this returns a list of lists rather than the flat list from the
original.
Any help is appreciate...just trying to be as Pythonesque as possible
:-)
Jeff
More information about the Tutor
mailing list