You just need the value of the dict

if podane_znaczenie == slownik[key]:

You could also write it as

for key, value in slownik.items():
    print ('Do you know the meaning of this character', key, '?')
    podane_znaczenie = input ('Meaning: ')
    if podane_znaczenie == value:
        print ('Yes!')
        continue

PS: continue is not needed here

Answer from blue note on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › how to compare user input to items in a dictionary?
r/learnpython on Reddit: How to compare user input to items in a dictionary?
March 20, 2016 -

I've recently began learning Python, and I'm trying to write a simple Q&A program. I want the user to be able to insert input and have it be compared to keys in a dictionary, and whichever key that has the most words in common with the question will be activated, and the answer will be printed. Here is my current code: from tkinter import * from tkinter import ttk from tkinter import messagebox

root = Tk()
root.geometry('{}x{}'.format(666, 666))
var = StringVar()
vara = StringVar()

resp = {'What programming language was this written in?': 'This program was written using Python 3.5. Python is a widely used high-level, general-purpose, dynamic programming language. Its syntax enables programmers to write code in fewer lines than more complex languages like Java and C++.', 'Who invented computer programming?': 'Charles Babbage is universally accepted as the father of computer programming due to his creation of the analytical engine. While computers were not created until a century beyond his invention, the analytical engine used an identical concept for input/output commands.', 'What coding language was used to create Windows OS?': 'Windows 7, 8, 8.1 and 10 operate on C++ and C# almost exclusively. Because these are lower-level languages, the programmer has greater control over the computer itself, enabling them to do many amazing things.'}


label = Message( root, textvariable=var,      relief=RAISED)
labelfont = ('times', 20, 'bold')

def callback():

    parabel = Tk()
    parabel.minsize(600, 400)
    parabel.maxsize(600,400)
    parabel.title("BonneyBot")

    pLabel = Label(parabel, text = "Welcome to     BonneyBot.").pack(side = TOP)
    pLabel1 = Label(parabel, text = "Ask a question about programming!").pack()
    pEntry1 = ttk.Entry(parabel, textvariable = vara)
    pEntry1.pack(side='top')

    def response():
        if pEntry1.get() in resp.keys():
                messagebox.showinfo('file',  resp[pEntry1.get()])
        else:
                messagebox.showwarning('error', 'I did not understand the question. Please ask again.')
        
            
    
    ttk.Button(parabel, text = "ASK AWAY!",     command=response).pack()
    
    


widget = Label(root, text="Welcome to my graduation project!\n This is a simple Q&A program created\n by Devin intended to assist individuals\n curious about computer programming.\n Click start to begin!")
widget.config(bg='lightblue', fg='red')
widget.config(font=labelfont)
widget.config(height=3, width=20)
widget.pack(expand=YES, fill=BOTH)
var.set("Let's get started!")


MyButton1 = Button(root, text="START", command=callback)
MyButton1.pack()



label.pack()
root.mainloop()

What could I add to compare the words in common with the user input with the keys in the dictionary? Thanks!

Top answer
1 of 4
2
First, you'd need a function that compares similiar words. You could use a simple set intersection for this: def compare(a, b): a = set(a.split()) b = set(b.split()) return len(a.intersection(b)) >>> compare('Hello World', 'Hi World') 1 A set intersection just returns the items that are present in both sets. This is somewhat crude, since it won't count the same word multiple times. It might work for you, though. If you don't mind external dependencies, I would recommend FuzzyWuzzy for better string comparisons. You can then use the max function, with your comparison function as the key. >>> max(resp.items(), key=lambda x: compare('What programming language', x[0])) ('What programming language was this written in?', 'This program was written using Python 3.5. Python is a widely used high-level, general-purpose, dynamic programming language. Its syntax enables programmers to write code in fewer lines than more complex languages like Java and C++.') This returns a tuple of the form (key, value) of the best matching dictionary item. Explanation: resp.items() creates a list of tuples of the form (key, value) from every item in the dictionary. The key argument of the max function is used to determine how the max item is chosen. What is given is applied to each item in the list you supplied to max. In this case, I'm using a lambda to call our compare(a, b) function with the users input as the first argument, and the first element of each tuple as the second argument. The first element of each tuple in the list is the key. The max function will then use the numbers returned by the comparison function to choose which item is the "max".
2 of 4
1
I'm pretty sure that I'd need to use a for loop of some kind but I have no clue how to realize this. Assistance is appreciated!
Discussions

python - How to compare user input with the keys of a dictionary? - Stack Overflow
I am trying to figure out how to compare my input with the keys of a dictionary. I want to print out the matching words with the dictionary and their value. It would be nice if someone could spent ... More on stackoverflow.com
🌐 stackoverflow.com
Python - How to compare user input to dictionary keys? - Stack Overflow
I've recently began learning Python, and I'm trying to write a simple Q&A program. I want the user to be able to insert input and have it be compared to keys in a dictionary, and whichever key ... More on stackoverflow.com
🌐 stackoverflow.com
March 20, 2016
python - Is there a better way to compare dictionary values - Stack Overflow
I am currently using the following function to compare dictionary values and display all the values that don't match. Is there a faster or better way to do it? match = True for keys in dict1: if More on stackoverflow.com
🌐 stackoverflow.com
comparing a user input to a dictionary in python - Stack Overflow
i'm trying to compare a user input to a dic in python, the program should take the student id as an input, and return the student grade. and the program should follow some rules: 1- the length of the More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 53933574 › how-to-compare-user-input-with-the-keys-of-a-dictionary
python - How to compare user input with the keys of a dictionary? - Stack Overflow
dictionary = {"nice":"0.5012", "awesome":"0.5766", "thankfull":"0.5891"} def PNV(saysomething): for token in nlp(saysomething): while True: if token in dictionary: print("the word", key, "is same as" + str(token) + 'with the value' + dictionary[value]) ... dictionary = {"nice":"0.5012", "awesome":"0.5766", "thankfull":"0.5891"} def PNV(saysomething): for token in nlp(saysomething): if token in dictionary: key = str(token) value = str(dictionary[token]) print("the word", key, "is same as" + str(token) + 'with the value' + value)
🌐
Miguendes
miguendes.me › the-best-way-to-compare-two-dictionaries-in-python
The Best Way to Compare Two Dictionaries in Python
April 29, 2024 - Learn how to compare two dicts in Python. Assert if two dicts are equal, compare dictionary keys and values, take the difference (deep diff), and more!
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-compare-dictionaries-on-certain-keys
Python - Compare Dictionaries on certain Keys - GeeksforGeeks
April 21, 2023 - Get the common keys in both dictionaries using set intersection operation. Create two sets, one for values of common keys in dict1 and another for values of common keys in dict2. Check if both sets are equal.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 36117533 › python-how-to-compare-user-input-to-dictionary-keys
Python - How to compare user input to dictionary keys? - Stack Overflow
March 20, 2016 - However, I want the user input ... "Who invented computer programming." Does that help? ... What you need to do is save the result of pEntry1.get() in a variable so you can compare it with each key present in the dicti...
🌐
Stack Overflow
stackoverflow.com › questions › 70806947 › comparing-a-user-input-to-a-dictionary-in-python
comparing a user input to a dictionary in python - Stack Overflow
That will let you compare correctly, but I think a better version would be the following: students = {11111: "A+", 22222: "B+", 33333: "D+"} ID = int(input("please enter the student ID:")) found = False if ID in students: print(students[ID]) found = True if not found: print("ID not found") if len(str(ID)) != 5: print("invalid Id") ... Sign up to request clarification or add additional context in comments.
🌐
Stack Overflow
stackoverflow.com › questions › 53490785 › comparing-user-input-to-a-dictionary-in-python
comparing user input to a dictionary in python - Stack Overflow
In the while loop, we are getting input every iteration. If it is 0, we break out of the loop. If not, we try to lookup the course in the dict. If this fails, we print the "error" message.
🌐
Scaler
scaler.com › home › topics › python program to compare dictionary
Python Program to Compare Dictionary- Scaler Topics
April 9, 2024 - The DeepDiff module is used to find the differences in dictionaries, iterables, strings, and other objects. Here, we'll use this module to do a Python dictionary compare.
🌐
Reddit
reddit.com › r/learnpython › comparing python dictionary values if one dictionary has values equal, or more than the another
r/learnpython on Reddit: Comparing Python dictionary values if one dictionary has values equal, or more than the another
March 30, 2021 -

Here is the scenario:

dict1 = { A : 1 , B : 3 , C: 0 }

dict2 = {C : 1, D : 2 , A : 1, B : 3 }

dict3 = {E : 1, B : 3, A : 1, C : 0}

Assuming dict1 is the baseline that subsequent dictionaries (dict2, dict3) need to be compared against, I am thinking about codes that check if dict 2 >= dict1 or dict 3 >= dict1:

  1. I understand dictionary is unordered, so does that mean that the dictionary can be compared without sort method?

  2. does extra elements in dict2 and dict3 affect the comparison operation, should my code factor extra elements?

  3. i think the best way would be something similar to cmp() in Python2, is any function similar to cmp() for dictionary? I don't intend to import any outside library, but okay with builtin modules.

I would like to some pointers to solve the question. Thank you for the help in advance!

Top answer
1 of 3
2
There is no way to compare dictionaries directly in Python3 and I think it is for the best. What should the comparison operators compare anyway ? Keys ? Values ? Their lengths ? Your dictionaries are pairs of items and its count, so it could make sense to compare them, but dictionaries generally can store anything, and I wonder how would the comparison work if we stored for example pairs of countries - their capital, what would be compared then. Even in your case, there might be some discussion, for example if A had bigger one count in one dict and B had bigger counter in second dict: first = {A : 3, B : 1} second = {A : 1, B : 2} #which one is bigger Would that mean that neither of them is bigger, since both have some value smaller then the other one ? Comparison operators usually provide a way to check which one is bigger, which would not be the case here. Long story short, it will be the best for you to write a function that compares 2 dictionaries the way you want it to and use that. Even the built-in collections.Counter() does not support comparison operators from reasons described above.
2 of 3
1
What exactly do you mean with dict 2 >= dict1? Like a subset? You should use sets for that, not dictionaries. https://docs.python.org/3/library/stdtypes.html#set You could convert your dictionaries to sets like this: set1 = set(dict1.keys()) # if you want to compare keys only set1 = set(dict1.values()) # if you want to compare values only set1 = set(dict1.items()) # if you want to compare both
🌐
AskPython
askpython.com › home › compare two dictionaries and check if key-value pairs are equal
Compare Two Dictionaries and Check if Key-Value Pairs are Equal - AskPython
February 15, 2023 - Now, we are going to look at how to check if the key: value pairs are equal in the dictionaries. It is also like a comparison only but in a bit more depth. For the following, we need to install “deepdiff” package. deepdiff is a python package for deep difference and search of any Python object/data.
🌐
Stack Overflow
stackoverflow.com › questions › 74250502 › how-can-i-compare-the-value-in-dictionary-to-the-input-value-from-users-python
list - How can I compare the value in dictionary to the input value from users? python - Stack Overflow
The best way to do this is to get all values in my_dict with my_dict.values(), then flatten that into one list of all the values (see this question for a variety of ways on how to flatten a list). Once you have a list of all the values in the dictionary, you can use a simply in comparison to check if the user's input is in that list.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-compare-two-dictionaries-in-python
How to Compare Two Dictionaries in Python - GeeksforGeeks
April 25, 2025 - If no mismatches are found, the else block prints True, indicating the dictionaries are equal. ... In Python, dictionaries are unordered collections of key-value pairs. Each item in a dictionary is accessed by its unique key, which allows for efficient storage and retrieval of data.
🌐
Archlinux
copyprogramming.com › t › comparing-user-input-integers-to-dictionary-values-python
Comparing User Input Integers To Dictionary Values Python - CopyProgramming
When I had to compare two dictionaries for the first time, I struggled―a lot!, For simple dictionaries, comparing them is usually straightforward., The reason is, Python has no built-in feature allowing us to: compare two dictionaries, numpy Values When we tried comparing two dictionaries with a, I also don't think that dictionary comprehension is the best way to compare the two dictionaries anyway ... Due to my use of a walrus ( := ) you will need at least python 3.8 for this, ("Input Series: ") name = [] wishlist = [] #allows the user to add as many items, Specifically, a list of dictionaries., The numbers key in each of these dictionaries is a set., python to turn 1, 2, 3, 4, 5, 6, 7 to an int