-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary1.py
More file actions
38 lines (23 loc) · 727 Bytes
/
Copy pathdictionary1.py
File metadata and controls
38 lines (23 loc) · 727 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
# Created by Roshan Jayswal on 20/04/2020.
# Copyright © 2021. All rights reserved.
# Update / add an element to the dictionary
myDict = {'name': 'Edy', 'age': 26}
myDict['address'] = 'London'
print(myDict)
# Traverse through a dictionary
def traverseDict(dict):
for key in dict:
print(key, dict[key])
traverseDict(myDict)
# Searching a dictionary
def searchDict(dict, value):
for key in dict:
if dict[key] == value:
return key, value
return 'The value does not exist'
print(searchDict(myDict, 27))
# Delete or remove a dictionary
myDict.pop('name')
# sorted method
myDict = {'eooooa': 1, 'aas': 2, 'udd': 3, 'sseo': 4, 'werwi': 5}
print(sorted(myDict, key=len))