I am just wondering if there is any better way of modifying the specific item in the list of list using List comprehension? In below example, I am squaring the second item of each list inside list, but, I don't want to eliminate inner list comprehension.
l = [
[1,2,3,],
[4,5,6,],
[7,8,9,],
]
nl = [[num**2 if i==1 else num for i, num in enumerate(x)] for x in l]
print nl
lin-place or create a new listnlwith list comprehension?for x in l: x[1] = x[1]**2