- 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 Odpowiedź
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)
...