Skip to content

Instantly share code, notes, and snippets.

View shaxbee's full-sized avatar

Zbigniew Mandziejewicz shaxbee

  • Chiang Mai, Thailand
View GitHub Profile
@shaxbee
shaxbee / flatten.py
Last active August 29, 2015 14:09 — forked from mrluanma/flatten.py
How to flatten a python nested list(tuple) - generator
#!/usr/bin/env python3
import collections
def flatten(t):
"""
Generator flattening the structure
>>> list(flatten([2, [2, (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]