1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| def not_the_same(user,other_user):
#deux users ne sont pas les m^mes s'ils ont des 'id' différents
return user["id"] != other_user["id"]
def not_friends(user,other_user):
#other_use is not a friend s'il n'est pas dans user["friends"]
#c'est le cas s'i n'est pas le même quetous les gens de user["friends"]
return all(not_the_same(friend,other_user) for friend in user["friends"])
##########################################################################
users=[{"id":0,"name":"Hero"},
{"id": 1,"name":"Dunn"},
{"id":2,"name":"Sue"},
{"id":3,"name":"Chi"},
{"id":4,"name":"Thor"},
{"id":5,"name":"Clive"},
{"id":6,"name":"Hicks"},
{"id":7,"name":"Devin"},
{"id":8,"name":"Kate"},
{"id":9,"name":"Klein"}
]
d = []
for ami in users[3]["friends"]:
print(ami["id"])
for fr in ami["friends"]:
print(" ",fr["id"])
if not_the_same(ami,fr) and not_friends(ami,fr):
#l'identation suivante est refusée
d.append(fr["id"]) |
Partager