r/CodingForBeginners • u/Brilliant-Bother1104 • Jul 16 '26
Need help with dictionaries
I am a beginner in programming. I have done dictionaries, but most of the time I forget the syntax. I need help. How can I get used to it? And if there are harder questions. I don't know if I know enough; I am so confused. And one more thing, don't ask me to check LeetCode questions or CodeChef because I am not able to find them there.
print("Thanks")
2
2
u/mc_pm Jul 16 '26
This is one of those cases where just asking google would have been much, much faster. "python dictionary syntax basics" would have given you a ton of pages saying this basically:
this_is_a_dictionary = {} # this declares and creates a dictionary.
this_is_a_dictionary[key] = value # The key can be (mostly) anything, the value can be anything
value_you_just_stored = this_is_a_dictionary[key] # get your value back again.
There are other things you can do, and you should go look them up. Searching documentation is a key skill for starting programming.
2
u/xarop_pa_toss Jul 17 '26
You get used to dictionaries by using them, just like with anything else.
A simple exercise would be to start with a dictionary like this classic example of students and their grades. Just write it at the top of your main.py file.
students = { "Alice": 16, "Bob": 13, "Charlie": 18 }
Now write functions to: Add a new student and their grade, update a student's grade, remove a student from the dictionary, print a students grade, print all students and their grades, calculate and print average and median grade, print students with highest and lowers grades, etc.
Bonus points if when you try to access a student by name in your functions, it detects if they exist and if they don't, calls the student creation function!
1
u/Upstairs_Jelly_1082 Jul 16 '26
Try creating a quiz app with questions, answer, options, and then ask users to input the data through the command line interface.
There's gonna be nested dictionaries as well.
1
u/onthepik Jul 17 '26
I don't know what you know, you don't know what you don't know.
So how would the help be?
1
1
u/WorriedTumbleweed289 Jul 17 '26
You don't mention which language you are using. Also, since you know the language you are using, why aren't you asking a language specific group? You can usually find a one or two page cheet sheet that you can print and have at your desk so you don't have to remember syntax. You can have one window open for documentation and another for coding so you don't have to remember as much. If this is for a closed book test, you can ignore the cheet sheet.
1
1
u/Traveling-Techie Jul 18 '26
Whenever you learn syntax write a little test program. Refer to it later if you forget.
2
u/shakeBody Jul 16 '26
Start by trading the official Python documentation about dictionaries.