how to flatten one level of list of lists?

Nick Perkins nperkins7 at home.com
Tue May 29 15:09:22 EDT 2001


import operator
ll = reduce(operator.add,l)

George Young:
> > I have a list like:
> >   l = [[2], [3], [5], [11]]
> > and I want to get:
> >   ll = [2, 3, 5, 11]
> >
> > I know I can do something like:
> >   ll = map(lambda i: i[0],l)
> >

Malcolm Tredinnick:
> ll = [x[0] for x in l]










More information about the Python-list mailing list