I am using python 3.7, and I need to modify multiple lists with the same set of ops - dedup & sort.
I wrote the below code, and can verify the lists are updated (with the print statements in the for loop) but the updates are lost outside of the loop (last print statement).
Here is my code:
for lst in list1, list2, list3, list4, list5:
print(len(lst)) # shows the original count before dedup
lst = list(set(lst))
lst.sort()
print(len(lst)) # shows the right count after dedup
print(list1) # shows the original list before dedup
I guess the for loop updates a copy of the list and not the original lists. I can run set and sort on the individual lists without a for loop but checking to see if there is a cleaner way to update tens of lists using a loop.