+ 6
How can i literate a nested list ?
Example: li=[1,2[3,4[23,66]],[2,4]] Output 1 2 3 4 23 66 2 4
7 ответов
+ 15
def fun(l):
for x in l:
if type(x) is list:
fun(x)
else:
print(x)
li = [1,2,[3,4,[23,66]],[2,4]]
fun(li)
+ 16
def chain(lst):
for i in lst:
if hasattr(i, '__iter__') and type(i) is not str:
yield from chain(i)
else:
yield i
print(list(chain(
[1, [2, [3, [4, 'abc',
[{'key1': 5, 'key2': 6}]
]]]]
)))
print(list(chain([1, 2, [3, 4, [23, 66]], [2, 4]])))
+ 5
Thank you Otterwerks ✌
+ 4
@ifang you are awesome 👍
+ 3
lpang 👍 for recursive function
+ 3
Thanks to all🙏
+ 3
And you too PyDan 👍