sopython
  • Chatroom
  • Common Questions
  • Wiki
  • Salad Language
  • Transcripts
  • Log In

Flattening a nested sequence

  • list
  • flatten
>>> a = [[1, 2, 3], [4, 5, 6]]
>>> b = [i for j in a for i in j]
# [1, 2, 3, 4, 5, 6]
  • How to make a flat list out of a list of lists?
  • Recursive generator for flattening nested lists
  • Flatten an irregular list of lists
  • Comprehension for flattening a sequence of sequences?
  • Flattening a shallow list in Python

Made by the cabbage addicts from the Python room on Stack Overflow.

This site is not affiliated with Stack Overflow. Contact us via chat or email.

sopython-site v1.7.1