-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict_sort.py
More file actions
41 lines (32 loc) · 772 Bytes
/
dict_sort.py
File metadata and controls
41 lines (32 loc) · 772 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
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Author : Ashutosh Kumar
PRN : 19030142009
Assignment - Program reads dictionary which contains student id and room number pair
and creates another dictionary which contains room number as keys which represent list of students staying in that room
"""
try:
#crearing a dictionary with values
dict={
1:104,
2:101,
3:101,
4:102,
5:103,
6:103,
7:102,
8:104,
9:101,
10:104
}
rooms_dict={}
for values in set(dict.values()):
rooms_dict[values]=[]
for keys in dict.keys():
rooms_dict[dict[keys]].append(keys);
print(rooms_dict)
except NameError:
print("No such name defined")
except TypeError:
print(" Type not defined")
except AttributeError:
print("No such Attribute")