+ 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?
6 Antworten
+ 6
Recursion would be useful for that problem.
+ 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.
+ 3
This might help
https://code.sololearn.com/c5iOBsdgp3Zi/?ref=app
+ 3
another way
https://code.sololearn.com/ccCOxaXww84i/?ref=app
+ 1
This seems to work too:
https://code.sololearn.com/cgr2lBqxQ2BA/?ref=app