Skip to content

Commit cb72a29

Browse files
committed
Added function "flatten" to flatten an iterable upto any level of nesting.
1 parent 6418617 commit cb72a29

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,15 @@ Usage:
6666
>>> list(idioms.random_digits(sentinel=8))
6767
[4, 2, 3, 2, 9, 5, 9, 3, 7, 7, 5, 5, 3, 5]
6868

69+
# Flatten nested iterators upto any level
70+
>>> list(flatten([1,[2,[3,[4,[5]]]]]))
71+
[1, 2, 3, 4, 5]
72+
>>> list(flatten([1,[2,3],[4,5]]))
73+
[1, 2, 3, 4, 5]
74+
>>> list(flatten(dict(enumerate(range(5)))))
75+
[0, 1, 2, 3, 4]
76+
>>> list(flatten([1,2,'python',{3:4, 4:5}, ['perl']]))
77+
[1, 2, 'python', 3, 4, 'perl']
78+
>>>
6979
>>> 'More coming soon!'
7080
'More coming soon!'

0 commit comments

Comments
 (0)