Python Forum
assign a value to a dict change all the values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
assign a value to a dict change all the values
#10
(Sep-21-2018, 02:43 AM)ichabod801 Wrote: You can't assign to a tuple index, so it won't work. This is an important point in Python. Mutables, like lists, dictionaries, and sets, display the behavior you see above. Immutables, like numbers, strings, and tuples, do not.

yes i know, what i wanted to check is if i can change the item pointed by a reference

from copy import deepcopy

x = [1, 2, 3]
y = (x, 4, 5)
print(y)

z = deepcopy(y)
x[1] = 7
print(y)
print(z)
and i can, please tell me if i am wrong: i can change it because the reference of 'x' inside y is always the same Dance
but so which is the difference between a normal copy and a shallow copy?
i am almost sure that i understood correctly the difference between a copy and a deep copy, the last one is completely a new object while the first is a reference to the original object
Reply


Messages In This Thread
RE: assign a value to a dict change all the values - by aster - Sep-21-2018, 01:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change row values by other row values from same df JosepMaria 3 2,348 Aug-28-2021, 10:15 PM
Last Post: eddywinch82

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020