Python 3. I'm trying to copy a list of a dictionaries without altering the original list. This doesn't seem to work the same way that copying a list does:
List of Dictionaries
list_of_dict = [{"A":"a", "B": "b"}]
table_copy = list(list_of_dict)
for x in table_copy:
x['B'] = 1
print(list_of_dict)
print(table_copy)
Yields
[{'A': 'a', 'B': 1}]
[{'A': 'a', 'B': 1}]
For reference this is how copying a list looks like this:
orig_list = [1,2,3]
copy_list = list(orig_list)
copy_list[1] = "a"
print(orig_list)
print(copy_list)
Yields what we expect
[1, 2, 3]
[1, 'a', 3]
How do you actually copy a list of dictionaries?