How To Use Dictionaries In Python (Python Tutorial #8)
Why Stack Overflow recommends it
Stack Overflow users link it when a newer Python programmer needs a quick, friendly introduction to dictionaries to simplify their code.
Recommended by 2 people across 2 different months, 2019 to 2021.
What it is
A short beginner tutorial from CS Dojo (episode 8 of his Python series) on Python dictionaries: creating them, looking up keys and values, and using them to store key-value data. A sample file accompanies the video.
What people said
Recommends user11931195 · 2019-09 · Stack Overflow · on “Writing optimized multiple conditional statements Or use any other way to check condition? in python”
I'm prerry new to python myself but you should be able to make your code better with dictionarys here is a link: [this video]
Recommends user14532940 · 2020-10 · Stack Overflow · on “How to find and print a dictionary key/value that matches user input?”
Thanks! It's all about practice, and you will get better. There is a great video by CS Dojo that helped me understand dictionaries, and I recommend you check it out here [this video]
Cites Greg W.F.R · 2021-08 · Stack Overflow · on “how to avoid a lot of repertitions of pattern?”
this is bad code in my opinion, I would rarely solve something using this technique. but assuming you insist on using this technique. You could use dict comprehension. (This might be advanced) What is "dict comprehension" guide: [LINK] I dont understand "enumerate" guide: [LINK] I have never heard of dictionaries guide: [this video] So the idea is that you store al your "text" variables as dictionary keys and al the values for it as dictionary values :) def stackoverflow(list): dictionary = {f"text{num+1}":text for num , text in enumerate(list.split('\n'))} if "text1" in dictionary: #check if this value exists print(dictionary["text1"]) # get the key from the dictionary and print its value return