Skip to content

Commit c90a948

Browse files
committed
Add dictionary sample code
1 parent 4a4099a commit c90a948

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

data_structures/dictionary/dict.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
greek = {'alpha': 1, 'beta': 2, 'gamma': 3}
2+
3+
greek['delta'] = 4 # add a key and coressponding value
4+
print(greek)
5+
6+
del greek['beta'] # delete item
7+
print(greek)
8+
9+
print(list(greek)) # return list of the dicitonary
10+
print(sorted(greek)) # return a new sorted instance of the iterable
11+
print(len(greek)) # return the number of items in the dictionary
12+
print(greek.get('delta')) # return the value coressponding given key
13+
14+
print('alpha' in greek) # testing
15+
print('zeta' in greek) # testing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numbers = {'one': 1, 'two': 2, 'three': 3, 'four': 4}
2+
for k, v in numbers.items():
3+
print(f'{k} -- {v}')

0 commit comments

Comments
 (0)