"count": 0
},
"mike": {
"count": 0
}
}
when I add data["james"]["count"] += 1, "mike" count value also update to 1
who can describe this issue ?
count for james and count for mike this is a link for the same object
It’s weird behaviour, beacuse type int is iimmutable data type. Two 0 are different objects in this case
Сan we to see your code?
Define your inner dicts with count separately! >>>count = {'count': 0} >>>data = { "james": count, "mike": count} >>>data {'james': {'count': 0}, 'mike': {'count': 0}} >>>data["james"]["count"] += 1 >>>data {'james': {'count': 1}, 'mike': {'count': 1}}
you can use this for comfort demonstration your code: https://pastebin.com/
ok, thx
Он понимает русский язык
Обсуждают сегодня