I tried to check values of a dictionary within a for loop with an if statement that has multiple conditions.
First I tried this code which didn't work:
d = {2312: 'Jim', 2323: 'Anna', 2314: 'Tim', 3054: 'Marc', 3574: 'Valerie', 3698: 'Nina'}
Smith = list()
Miller = list()
for name in d.values():
if name == 'Jim' or 'Anna' or 'Tim':
Smith.append(name)
else:
Miller.append(name)
print(Smith)
print(Miller)
Then I tried this which worked:
d = {2312: 'Jim', 2323: 'Anna', 2314: 'Tim', 3054: 'Marc', 3574: 'Valerie', 3698: 'Nina'}
Smith = list()
Miller = list()
for name in d.values():
if name == 'Jim' or name == 'Anna' or name == 'Tim':
Smith.append(name)
else:
Miller.append(name)
print(Smith)
print(Miller)
My question is why does the first one not work but the second code does?
And is there a 'easier' code to check this?