[issue27852] itertools -> flatten_all()

YoSTEALTH report at bugs.python.org
Thu Aug 25 17:59:36 EDT 2016


YoSTEALTH added the comment:

Currently there is flatten() function in itertools Recipes section. This is what it does:
-> a = ['one', 'plus', [b'two', b'three'], ['four', ('five', (1, {'e', 'ee'}, (2, (3, ))), ['six'])], generator()]
<- ['o', 'n', 'e', 'p', 'l', 'u', 's', b'two', b'three', 'four', ('five', (1, {'ee', 'e'}, (2, (3,))), ['six']), 0, 1, 2]

As you can see it only flattens 1 nested level and for some reason it explodes the 'one' and 'plus' str items (maybe intentionally designed or lazily ignored, i don't know).

This is useful maybe in special circumstances where you have:
-> a = [[1, 2, 3], ['one', 'two', 'three']]
<- [1, 2, 3, 'one', 'two', 'three']

Also it doesn't work with bytearray, memoryview ...


In real worldly use something like flatten_all() is more useful!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27852>
_______________________________________


More information about the Python-bugs-list mailing list