+ 2

Flatten the list

Input: [1,2,[3,[4,5,6],[7,8,9]],10,11] Output: [1,2,3,4,5,6,7,8,9,10,11] I have no idea how to do this. Can somebody help?

27th Dec 2019, 8:22 AM
Geek
Geek - avatar
7 Respuestas
+ 6
Recursion would be useful for that problem.
27th Dec 2019, 8:24 AM
Seb TheS
Seb TheS - avatar
+ 6
You can check whether an item is a list by isinstance method: isinstance(item, list) This means that item belongs to the list class.
27th Dec 2019, 8:36 AM
Seb TheS
Seb TheS - avatar
27th Dec 2019, 9:05 AM
Rik Wittkopp
Rik Wittkopp - avatar
28th Dec 2019, 5:04 AM
Vitaly Sokol
Vitaly Sokol - avatar
30th Dec 2019, 9:06 AM
Zuke
Zuke - avatar