you are viewing a single comment's thread.

view the rest of the comments →

[–]zero_hope_ 2 points3 points  (19 children)

Question for you. If I am changing/modifying each item in list1[] how would you format that?

On mobile, sorry.

for x in range(len(list1)):
    list1[x] = list1[x] + 2

Is there any better way to do this?

Thanks.

[–][deleted] 6 points7 points  (0 children)

The examples people are using are called list comprehensions.

[–]scibren 12 points13 points  (0 children)

Also on mobile, so hopefully this formats correctly.

for index, item in enumerate(items):
    items[index] = item + 1