i have this list and want to add 1 to every second element . i don't care about first element
actual_high_points = []
high_points = [[3.0, 134.39999389648438], [12.0, 134.25],
[17.0, 135.0], [21.0, 134.89999389648438], [26.0, 134.64999389648438],
[34.0, 134.9499969482422], [39.0, 135.10000610351562], [46.0, 135.3000030517578]]
currently i am doing this but i want to do inplace if possible .
actual_high_points.extend([[high_points[0],high_points[1] 1]])
CodePudding user response:
Use a for
loop to operate in place:
for l in high_points:
l[1] = 1
CodePudding user response:
You could also use list comprehension to achieve the same:
high_points = [[3.0, 134.39999389648438], [12.0, 134.25],
[17.0, 135.0], [21.0, 134.89999389648438], [26.0, 134.64999389648438],
[34.0, 134.9499969482422], [39.0, 135.10000610351562], [46.0,
135.3000030517578]]
actual_high_points = [[*list, item 1] for *list,item in high_points]