I need to a function that would reset the list to its orginal state so in order to do that I would use the copy of a list as its the most straightforward way to achieve it.
Every time I make changes to a list(or number of lists) I would like to have a list in its orginal state. Since the number of lists can be bigger I need a function that can deal with it without repating several lines of code everytime.
I tried to make a function that would simply create a copy of a list and thus I could use it to get a a copy of orginal list for further alterations. But there is something that I am missing because im getting error:
list1=[1,2,3]
list2=['a','b','c']
list3=[434,52,43]
def copy_lists():
list1c=list1[:]
list2c=list2[:]
list3c=list3[:]
copy_lists()
list1c.append('b')
copy_lists()
#now list1c should be back to orginal
print(list1c)
---------------------------------------------------------------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-95468ead1e78> in <module>()
9
10 copy_lists()
---> 11 list1c.append('b')
12 copy_lists()
NameError: name 'list1c' is not defined