Liam Clarke wrote:
Hi,

Is there a way to apply multiple actions within one list comprehension?

i.e. instead of

a = []
for i in x:
    i.pop(3)
    g = [ int(item) for item in i]
    a.append(g)

You can nest list comps. Except for the pop, the above can be written a = [ [ int(item) for item in i] for i in x ] which is pretty readable.

There is probably some way to get the pop in there too but I avoid list comps with side effects as bad style.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to