![]() However, consider this slightly more complex case: > obj =, , 6, 'abc',, ]] In the case of obj =, , ], all of the solutions here are good, including list comprehension and _iterable. six is also a third-party package, though it is stable. Note: Below applies to Python 3.3+ because it uses yield_from. If you don't like/want such behavior, you can use the following version which filters out from flattening iterables like strings and bytes: def flatten(itr): N.B.: Since all iterables are flattened, strings are decomposed into sequences of single characters.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |