109 days ago · 6 min read1278 words · Tech · hide · Fediverse post

Python A-Z is a blog series about Python. Each day, I share insights, ideas and examples for different parts of Python development that match with the letter of the day. Blaugust is an annual blogging festival in August where the goal is to write a blog post every day of the month. Dictionary is a data structure in Python that in other contexts and languages is called an associative array, akey-value store or a map. It’s a handy and efficient data structure for when you need to store and retrieve a value based on a key. This is a 101 level introduction to dictionaries. Dictionary Creating a dictionary The basic form of dictionary can be created in couple of ways: # dict constructor with keyword arguments scores = dict(Charlie=10, Patty=25, Snoopy=30) # dict constructor with tuples scores = dict(('Charlie', 10), ('Patty', 25), ('Snoopy', 30)) # key: value pairs scores = { 'Charlie': 10, 'Patty': 25, 'Snoopy': 30 } # dict comprehension data = [('Charlie', 10), ('Patty', 25), ('Snoopy',…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town