0

What is dictionary key in python

19th May 2019, 2:34 AM
Rekha Singh
Rekha Singh - avatar
1 Respuesta
+ 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]
19th May 2019, 10:12 AM
Lothar
Lothar - avatar