6. Python - Dictionaries

 dictionaries: // like maps

map = {'key' = 5}

map['key']

map['newkey'] = 55 // adds a new key and value. can also change existing keys


Dictionary comprehension:

dictionary = [1,2,3,5]

test = {element: 1 for element in dictionary} // returns each number and a key and put in dictionary


Methods:

'Key' in dictionaryname // returns true or false if key is in dictionary

dictionary.keys() // return all keys

dictionary.values() // return all values


Loop Dictionaries:

for key in dictionaries:

    print("{} = {}".format(key,dictionaries[key]))

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort