- 1
Write a tuple of users, where users are of type dictionary and have the fields: ânameâ â string type âageâ â int type
Write a tuple of users, where users are of type dictionary and have the fields: ânameâ â string type âageâ â int type âsubjectsâ â list type For example: [{ânameâ: âSamâ, âageâ:20, âsubjectsâ: [âAâ,âBâ,âCâ]}, {ânameâ: âBartâ, âageâ:20, âsubjectsâ:[âAAâ,âCâ]}, {ânameâ: âErikâ, âageâ:21, âsubjectsâ:[âAâ,âBâ]}] Find the user who has more subjects than the others, and change his/her name to âSuper Geekâ.
1 RĂ©ponse
0
The example is wrong as it is a list [], and not a tuple (,,,).
user1 = {ânameâ: âSamâ, âageâ:20, âsubjectsâ: [âAâ,âBâ,âCâ]}
user2 = ...
user3 = ...
allusers = (user1, user2, user3,)
nbsubjects=0
geek = None
for user in allusers:
if len(user['subjects']) > nbsubjects:
nbsubjects = len(user['subjects'])
geek = user
print(geek)
...