-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionnaire.py
More file actions
30 lines (22 loc) · 784 Bytes
/
Copy pathdictionnaire.py
File metadata and controls
30 lines (22 loc) · 784 Bytes
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
# -*-coding:Latin-1 -*
inventaire = dict()
inventaire["pommes"] = 22
inventaire["melons"] = 4
inventaire["poires"] = 18
inventaire["fraises"] = 76
inventaire["prunes"] = 51
#On met l'inventaire dans une liste pour tier
inventaireinverse = list()
for i, fruit in enumerate(inventaire):
#print("{} - {} - {}".format(i, fruit, inventaire[fruit]))
inventaireinverse.append((inventaire[fruit], fruit))
#for fruit in enumerate(inventaireinverse):
# print(fruit)
#On inverse le tri
inventaireinverse.sort(reverse=True)
#On recrée le dictionnaire sur la liste triée
inventaire = dict()
for i, fruit in enumerate(inventaireinverse):
inventaire[fruit[1]] = fruit[0]
for cle, fruit in enumerate(inventaire):
print("{} - {} - {}".format(cle, fruit, inventaire[fruit]))