create a list of each element after an iteration of list comprehension

Understanding of list comprehension is needed here and it also depends on where you put the square brackets

y=[[1,1,1],[2,2,2]]

yb1=[[j+1 for j in i] for i in y]

print(yb1)

Output:

[[2, 2, 2], [3, 3, 3]]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top