+ 2
Why does it work like this ?
I don't understand why each element of the list is fist splited, and then turned into a list : x = ['abc', 'defg'] y = list(map(list, x)) print(y) At first, I expected the output to be like : "[['abc'], ['defg']].
3 odpowiedzi
+ 6
Ali_combination
As you have passed list function in a map function so map function will convert each item to a list so 'abc' will be converted in ['a', 'b', 'c']
Same for 'defg' so result is
[['a', 'b', 'c'], ['d', 'e', 'f', 'g']]
+ 4
List creates a mutable sequence from a string iterator, and the string as a whole can become a list element when using the append method or representing the string via a list comprehension:
print([ [s] for s in ["do", "smth"] ])
+ 2
Vitaly Sokol I see thanks.