0
What is dictionary key in python
2 Answers
+ 4
Data structures in python
Data structures in python are lists, tuples, sets and dictionaries. Each of these structures has its strengths and weaknesses.
Dictionaries always consists of a key - value pair. For getting short access times the key field is stored as a hash - so only unique expressions are valid as a key.
Values can consist of any data type. This means string, int and float numbers, but also of objects. This can be lists and so on.
Creating a dict:
cor_dic = {1: 0.0215, 2: 0.0241,...}
morse_dic = {âSâ: âsssâ, âOâ: âlllâ,...}
col_dic = {âredâ: [0,0,0], âgreenâ:...}
Accessing a dict:
cor_dic = {1: 0.0215, 2: 0.0241}
print(cor_dic.get(1))
#result: 0.0215
col_dic = {"red": [255,0,0], "green": [0,255,0]}
print(col_dic.get('green'))
#result: [0,255,0]