Showing posts with the label Dictionaries

Python Programming Language - Dictionaries

Dictionaries are unordered collections of key-value pairs. They are used when you need to assign a value to each of the keys and be able to quickly access the value by knowing the key. In other languages, dictionaries are usually called map, hash, or object. Dictionaries are optimized for data retrieval. To extract the value, you need to know the key. The syntax of a dictionary definition is as follows: dictionary = { key1:value1, key2:value2, ....} In curly braces, the sequence of elements is indicated by commas, with the key and its value separated by a colon for each element. Let's define a dictionary: twd = { 1 : "Rick" , 2 : "Daryl" , 3 : "Shane" } In a twd dictionary, a number is used as a key and a string as a value. For example, an element with a key of 1 has a value of "Rick", an element with a value of "Daryl" and so on. Another example: twd = { "" : "Carl" , "" : &q