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
#4
Windspar thank you for your second example i didn t know about shallow copy

Anyway i think that my problem isn t caused by the absence of a shallow copy

Posting that stackexchange i brought you outside the road sorry
As Larz60+ suggested this is my aim:
In my code i am creating a dict with random numbers (dict_p) then i would like to add (append) this dict to a list (list_p)
This is my output
[{'test': 'gamma', '12': 3.89, 'NG': 0.06, '1': 2.82, '2': 4.31, 'GG': 0.95}, {'test': 'gamma', '12': 3.89, 'NG': 0.06, '1': 2.82, '2': 4.31, 'GG': 0.95}, {'test': 'gamma', '12': 3.89, 'NG': 0.06, '1': 2.82, '2': 4.31, 'GG': 0.95}]
It shouldn t be all the same. For some reason that i don t understand the list is filled always with the last appended dict
I would like that is was filled with different random generated dict
Reply


Messages In This Thread
RE: assign a value to a dict change all the values - by aster - Sep-18-2018, 11:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change row values by other row values from same df JosepMaria 3 2,303 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