New course! Every coder should learn Generative AI!
Try a free lesson0
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
1 Answer
+ 1
Python do not add list and number. Instead of A+a[index], try A + [a[index]].