flatten¶
-
sknano.core.itertools.
flatten
(items, ignore_types=(<class 'str'>, <class 'bytes'>))[source] [edit on github][source]¶ Yields single sequence of values with no nesting [PythonCookbook]
Parameters: - items (sequence) – nested sequence that you want to flatten into a single sequence with no nesting
- ignore_types (
tuple
, optional) –tuple
ofIterable
type
s to that should not be interpreted asIterable
s to be flattened. Default is (str
,bytes
) to prevent strings and bytes from being interpreted as iterables and expanded as individual characters.
Yields: sequence – single sequence with no nesting
Examples
>>> items = [1, 2, [3, 4, [5, 6], 7], 8] >>> from sknano.core import flatten >>> items = list(flatten(items)) >>> print(items) [1, 2, 3, 4, 5, 6, 7, 8]