flattenonly¶
- emlib.iterlib.flattenonly(l, types)[source]¶
Flatten only if subsequences are of type ‘type’
- Parameters:
l – a seq
type – a type or a tuple of types, as passed to isinstance
Example
flatten only list items, pass tuples untouched
>>> l = [1, [2, 3], (4, 5)] >>> list(flattenonyl(l, list)) [1, 2, 3, (4, 5)]