Jun-29-2022, 02:15 PM
(This post was last modified: Jun-29-2022, 03:42 PM by Yoriz.
Edit Reason: Added code tags
)
1. create a list named All_Items_List
2. set All_Items_List_Copy = All_Items_List
3. create Subset_list which has one less item than All_Items_List and All_Items_List_Copy
4. remove all items from All_Items_List_Copy that exist in Subset_List
5 result is all items removed from All_Items_List_Copy are also removed from All_Items_List
I thought that after setting All_Items_List_Copy= All_Items_List, that All_Items_List_Copy would be separate from All_Items_List
Below is the code used:
2. set All_Items_List_Copy = All_Items_List
3. create Subset_list which has one less item than All_Items_List and All_Items_List_Copy
4. remove all items from All_Items_List_Copy that exist in Subset_List
5 result is all items removed from All_Items_List_Copy are also removed from All_Items_List
I thought that after setting All_Items_List_Copy= All_Items_List, that All_Items_List_Copy would be separate from All_Items_List
Below is the code used:
All_Items_List = ["a","b","c","d","e","f","g","h"] All_Items_List_Copy=All_Items_List Subset_List = ["a","b","c","d","e","f","g"] # "h" is missing from subset list print("All_Items_List = ",All_Items_List ) print("All_Items_List_Copy = ",All_Items_List_Copy) print("Subset_List = ",Subset_List) print(" ") for items in Subset_List : All_Items_List_Copy.remove(items) print("All_Items_List = ",All_Items_List ) print("All_Items_List_Copy = ",All_Items_List_Copy) print("Subset_List = ",Subset_List) Output from the code: All_Items_List = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] All_Items_List_Copy = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] Subset_List = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] # "h" is missing from the Subset_List All_Items_List = ['h'] All_Items_List_Copy = ['h'] Subset_List = ['a', 'b', 'c', 'd', 'e', 'f', 'g']why does removing items from the All_Items_List_Copy also remove the same items from All_Items_List ?