All about dict in python

Minseo Chayabanjonglerd
MikkiPastel
Published in
1 min readJun 2, 2017
credit : https://pixabay.com/en/dictionary-reference-book-learning-1619740/

dict is a data type in python language
dict have key and value which same is list in C#

create new dict
num = {‘one’: 1, ‘two’: 2, ‘three’: 3}

get dict size
len(num)

get all dict key
num.keys()

get all dict value
num.values()

add new data in dict
num[‘four’] = 4

print for each key and value in dict
for key, val in num.items():
print (key, val)

update value in some key
num[‘one’] = ‘11’

delete dict
num.clear()

for sort key, output is list data type
sorted(num)

for sort value, output is list data type
sorted(num.value)

for sort by key and show all member in dict, output is tuples data type
sorted(num.items(), key=lambda x:x[1])

--

--

Minseo Chayabanjonglerd
MikkiPastel

Android Developer | Content Creator AKA. MikkiPastel | Web2 & Web3 Contributor