0

Why is the output of this code 7?

x=[[0],[1]] print(len(' '.join(list(map(str,x)))))

10th Jan 2019, 7:06 AM
Խաչատուր Դալլաքյան
Խաչատուր Դալլաքյան - avatar
2 Answers
+ 4
Try putting this in the code and you will see: print(list(map(str,x))) x is a list that has two lists as elements, and each inner list has a number inside. First, str converts those inner lists to string which looks like this: '[0]', '[1]' So these strings are 3 characters long each (including the brackets). Then they are joined by a whitespace so the final string is: '[0] [1]' which is 7 characters long, thus the result.
10th Jan 2019, 7:16 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Thanks a lot
10th Jan 2019, 7:18 AM
Խաչատուր Դալլաքյան
Խաչատուր Դալլաքյան - avatar