This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author YoSTEALTH
Recipients YoSTEALTH
Date 2016-08-24.17:29:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472059790.24.0.14619033581.issue27852@psf.upfronthosting.co.za>
In-reply-to
Content
# Maybe a Recipe for itertools

from collections.abc import Iterable

def flatten_all(iterable):
    # -> 'one'
    # <- ['one']
    # -> ['one', [b'two', b'three'], ['four', ('five', (1, {'e', 'ee'}, (2, (3, ))), ['six'])], generator()]
    # <- ['one', b'two', b'three', 'four', 'five', 1, 'ee', 'e', 2, 3, 'six', 0, 1, 2]

    if isinstance(iterable, Iterable) and not isinstance(iterable, (str, bytes)):
        for it in iterable:
            yield from flatten_all(it)
    else:  # int & others types as is.
        yield iterable


if __name__ == "__main__":

    # Test Only
    def generator():
        for i in range(3):
            yield i

    a = ['one', [b'two', b'three'], ['four', ('five', (1, {'e', 'ee'}, (2, (3, ))), ['six'])], generator()]
    # a = 'one'
    # a = (True, False)

    print(list(flatten_all(a)))
History
Date User Action Args
2016-08-24 17:29:50YoSTEALTHsetrecipients: + YoSTEALTH
2016-08-24 17:29:50YoSTEALTHsetmessageid: <1472059790.24.0.14619033581.issue27852@psf.upfronthosting.co.za>
2016-08-24 17:29:50YoSTEALTHlinkissue27852 messages
2016-08-24 17:29:49YoSTEALTHcreate