Skip to content

Instantly share code, notes, and snippets.

View seanwu1105's full-sized avatar
💱
Write colorful texts on a dark screen for living.

Shuang Wu seanwu1105

💱
Write colorful texts on a dark screen for living.
View GitHub Profile
@seanwu1105
seanwu1105 / flatten.py
Created July 14, 2018 02:26 — forked from ma-ric/flatten.py
Python; recursive flatten of nested iterables, with proper handling of string elements
#!/usr/bin/env python3
import collections
def flatten(t):
"""
Generator flattening the structure
>>> list(flatten([2, [2, "test", (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, "test", 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
"""