Posted By

iamok on 05/06/09


python lists sum

Versions (?)

flattening list

 / Published in: Python


  1. '''
  2. Use sum() on the outer list and prime it with an empty list, []. Python will concatenate the inner lists, producing a flattened list.
  4. More alternative on the URL
  5. '''
  6. alist = [['a', 'b'], ['c'], ['d', 'e', 'f']]
  7. print sum(alist, [])
  8. -output-
  9. ['a', 'b', 'c', 'd', 'e', 'f']

Report this snippet  

You need to login to post a comment.