Beginners Guide to Python, Part2: Dictionaries
Not to be mistaken for the Oxford Dictionary….
Welcome back! I hope you found ‘Beginners Guide to Python, Part1: Lists’ insightful. Even if it only helped a tiny bit, that’s still a win for me! My goal is to help and encourage you on your Python and machine learning journey. It wasn’t too long ago that I was an absolute nooooob at coding. I still consider myself a novice, but with persistence and even 30 minutes a day, you’ll start to see progress.
In our ‘Beginners Guide to Python, Part2: Dictionaries’, we will explore how to use and manipulate Python dictionaries. Dictionaries are a slightly more difficult concept to grasp, but I’m sure we can go from noob to pro in no time!
Just as real dictionaries have a definition assigned to a word, in Python we assign a value to a key {Key : Value}
. Dictionaries are enclosed in ‘squiggly’ brackets as shown above, with a colon separating our value and key. Looking back to, ‘Beginners Guide to Python, Part1: Lists’ we know this is called syntax!
We could for instance use a dictionary to associate a location with a zip/postcode. You could assign your friends as keys and their phone numbers as values.
Note: Dictionary keys and values are not limited to just strings and integers. Values can be any…