Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • it fails when all elements are not list. (e.g. lst=[1, [2,3]]). of course integer is not iterable. Commented Sep 8, 2020 at 8:32
  • 2
    also, mind that list of strings will be flattened to a list of characters Commented Oct 30, 2020 at 2:05
  • 1
    I'd reverse the answer, emphasizing collapse over flatten (leaving it for special case of pure lists of lists). Commented Apr 19, 2023 at 19:23