Can anyone explain? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone explain?

I came across this code when I was looking for help in the Q&A section. I looked up what enumerate does so I have some understanding of it, but I don’t get lines 7-8. Can anyone explain how this code works? a = [3,2,1] b = [[1,2,3], [4,5,6]] c = [] for i in b: d = [] for index, A in enumerate(i): d.append(A+a[index]) c.append(d) print(c) I modified the code a little to help me understand it. This is the original code from the post: https://www.sololearn.com/discuss/1311492/?ref=app

12th Jul 2020, 3:20 AM
•—• • •-• ••• —- -•
•—• • •-• ••• —- -• - avatar
1 Answer
+ 1
Python do not add list and number. Instead of A+a[index], try A + [a[index]].
12th Jul 2020, 3:48 AM
Esch
Esch - avatar