I'm counting occurrences of certain objects within the same backup file:
with open(file_path, encoding='utf-8') as data:
backend_data = json.load(data)
users = {}
sessions = {}
for key in backend_data.keys():
users.update(backend_data[key]['users'])
for key, value in users.items():
if 'session' in value:
sessions.update(value['session'])
print(len(users))
print(len(sessions))
While I always get the same len
result for users, the len
for sessions differs almost each time I call my script.
The file is located on my hard drive and isn't altered in any way during the runs. Here are some sample results of 5 runs:
// 1.
users: 819
sessions: 2373
// 2.
users: 819
sessions: 1995
// 3.
users: 819
sessions: 2340
// 4.
users: 819
sessions: 2340
// 5.
users: 819
sessions: 2069
Some additional information about the file: It's 34535 lines long and has a size of 959kb.
Why do I get different values for one dictionary but not for the other, when I run my script multiple times?