Kindly show me a better way to do it
Chris Rebert
clp2 at rebertia.com
Sat May 8 16:55:30 EDT 2010
On Sat, May 8, 2010 at 1:41 PM, Oltmans <rolf.oltmans at gmail.com> wrote:
> Hi, I've a list that looks like following
>
> a = [ [1,2,3,4], [5,6,7,8] ]
>
> Currently, I'm iterating through it like
>
> for i in [k for k in a]:
> for a in i:
> print a
>
> but I was wondering if there is a shorter, more elegant way to do it?
Just use a different variable name besides `a` in the nested loop so
you don't have to make the copy of `a`. I arbitrarily chose `b`:
for i in a:
for b in i:
print b
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list