+ 3

how unpack Nested list?

example 1: for example lst = [1, 2, [3, [4, 5, [6]], 7], 8] now how unpack it like this >>> [[1, 2, 8], [3, 7], [4, 5], [6]] example 2: lst = [1, [2, [[6]]], [[[7]]]] >>> [[1], [7], [7], [7], [2, 6], [6]]

6th Apr 2021, 8:55 AM
imAlireza
imAlireza - avatar
1 Respuesta
+ 1
You can do that if you use the same nesting structure on the left side: ``` a, (b, c) = [1, [2, 3]] print(f"{a=} {b=} {c=}") ``` Also you can add extra parentheses to demonstrate the same structure and make it a little bit clear: ``` (a, (b, c)) = [4, [5, 6]] print(f"{a=} {b=} {c=}") ``` https://code.sololearn.com/cIPr0kwXyn8L/?ref=app
25th Jan 2023, 11:12 AM
Евгений
Евгений - avatar