Create a Python Dictionary
A dictionary in Python is an ordered collection of stored data like map values. Whereas a dictionary holds two values, many other data types only contain one value. This wikiHow will teach you how to create a dictionary in Python.
Steps
- Open your Python interpreter software. This is the Python software you Install Python.
- Go to https://www.python.org/downloads/ and click the appropriate link to download the software (the website will automatically give you links to download the software for your Mac or Windows operating system).
- It opens to look like a command line prompt or Terminal.
- Name your dictionary. You'll enter this name at the end to see if your dictionary is working, but you can use any phrase or word for the name. This example uses "this dict" as the dictionary name.
- Enter your dictionary values between curly brackets and use a colon between your value and key. You should have code that looks like this:Template:Codebox
- Duplicates are not allowed. The newest entry that duplicates a key value will overwrite the previous value.
- Press Enter or Return on your keyboard to continue.
- Enter print(thisdict)and press ↵ Enter or ⏎ Return on your keyboard. This code is to test your dictionary coding. If the test does not show the correct results (it doesn't show your entire library), then you may have typed it incorrectly. Make sure the quotes and commas are where they should be and try the print code again.
References
Quick Summary
Template:Summary:Create-a-Python-Dictionary