You should iterate over keys with:

Copyfor key in mydictionary:
   print "key: %s , value: %s" % (key, mydictionary[key])
Answer from systempuntoout on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-key-from-value-in-dictionary
Get Key from Value in Dictionary - Python - GeeksforGeeks
d2.get(val): Looks up the original key for the given value. Since only one key can correspond to a value, this method works best when values are unique. This method iterates over the dictionary using a for loop, checking each key-value pair.
Published   July 11, 2025
Discussions

Is there a way to find a key in a dictionary with only knowing the value?
You will need to iterate: result = [key for key, value in my_dictionary.items() if value == 93] More on reddit.com
🌐 r/learnpython
11
13
October 28, 2022
What is the most pythonic way of getting an object from a dict when the key may not exist?
You're asking two different questions. What is the most pythonic way of getting an object from a dict when the key may not exist? dict.get(key, default) What is the most pythonic way of doing one thing if a key exists and doing another if it doesn't? if key in dict: # Do the thing else: # Do something else More on reddit.com
🌐 r/learnpython
16
2
April 15, 2023
What does get() mean and do in Python?
There is no "get() method in Python" as though it were a universal feature of the language. Each class defines its own methods, and two methods with the same name in different classes are entirely separate from each other. As for the get() of a dictionary, this writeup is short and to the point. https://www.w3schools.com/python/ref_dictionary_get.asp get() on a dictionary returns the value of the key you specify (like mydict[key] does). But if the key doesn't exist, it returns None (instead of throwing an exception), or you can specify what value to return in that case via an optional second argument. More on reddit.com
🌐 r/learnpython
7
2
March 17, 2025
When to use dict.get in Python (timing)
Just 5c, dict.get is slowed down by member lookup ("dots are expensive"). If you are calling it in an inner loop (which is the only time you care about perf), you can alias it somewhere outside the loop to a local function. More on reddit.com
🌐 r/Python
40
82
January 18, 2022
🌐
W3Schools
w3schools.com › python › ref_dictionary_keys.asp
Python Dictionary keys() Method
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else · Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Matplotlib Intro Matplotlib Get Started Matplotlib Pyplot Matplotlib Plotting Matplotlib Markers Matplotlib Line Matplotlib Labels Matplotlib Grid Matplotlib Subplot Matplotlib Scatter Matplotlib Bars Matplotlib Histograms Matplotlib Pie Charts
🌐
Programiz
programiz.com › python-programming › methods › dictionary › get
Python Dictionary get()
The get() method returns the value of the specified key in the dictionary.
🌐
Codecademy
codecademy.com › learn › dacp-python-fundamentals › modules › dscp-python-dictionaries › cheatsheet
Python Fundamentals: Python Dictionaries Cheatsheet | Codecademy
This method takes the key as the first argument and an optional default value as the second argument, and it returns the value for the specified key if key is in the dictionary. If the second argument is not specified and key is not found then None is returned. ... Python dictionaries can remove key-value pairs with the .pop() method.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-dictionary-keys-as-a-list
Dictionary keys as a list in Python - GeeksforGeeks
The unpacking operator (*) can be used to extract keys directly. ... The unpacking operator expands the dictionary keys into a list.
Published   July 11, 2025
🌐
Reddit
reddit.com › r/learnpython › what is the most pythonic way of getting an object from a dict when the key may not exist?
r/learnpython on Reddit: What is the most pythonic way of getting an object from a dict when the key may not exist?
April 15, 2023 -

QUESTION:

There are two ways to get an item from a dict. Referencing the item with "dict[key]" or calling "dict.get(key)".

If the item doesn't exist, dict[key] raises KeyError, whereas dict.get(key) return None.

Which of these is more pythonic?

try:
    value = dict\[key\]
except KeyError as ke:
    \# Do something else

Or

value = dict.get(key)

if value == None:
   \# Do the thing
else:
   \# Do something else

==========================================

UNNECESSARY CONTEXT FOR COMPLETIONISTS:

I am writing a program that imports objects and maps their relationships as a tree.

Part of the processing involves a dict that tracks partial relationships between entities. If I have already processed the item's parent, then it's easy for me to look up the parent's entire path to the root of the tree in a dict based on the parent's identifier. Then I just create a new dict entry which is "parent's path + child". Usually, this works, but sometimes the object's parent hasn't been processed yet. I do some special processing when I detect that the parent's path hasn't been discovered.

🌐
Note.nkmk.me
note.nkmk.me › home › python
Get Keys from a Dictionary by Value in Python | note.nkmk.me
May 19, 2025 - You can get dictionary keys based on their values using a list comprehension with the items() method.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python get dictionary keys as a list
Python Get Dictionary Keys as a List - Spark By {Examples}
May 31, 2024 - How to get Python Dictionary Keys as a List? To get all dictionary keys as a list in Python use the keys() method and covert the returned object to a list
🌐
W3Schools
w3schools.com › python › python_dictionaries_access.asp
Python - Access Dictionary Items
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else · Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Matplotlib Intro Matplotlib Get Started Matplotlib Pyplot Matplotlib Plotting Matplotlib Markers Matplotlib Line Matplotlib Labels Matplotlib Grid Matplotlib Subplot Matplotlib Scatter Matplotlib Bars Matplotlib Histograms Matplotlib Pie Charts
🌐
Vultr Docs
docs.vultr.com › python › standard-library › dict › keys
Python dict keys() - Retrieve Dictionary Keys | Vultr Docs
November 11, 2024 - You will explore examples that ... capabilities in Python. Define a dictionary with some key-value pairs. Use the keys() method to get the keys....
🌐
Tutorialspoint
tutorialspoint.com › python › dictionary_get.htm
Python dictionary get() Method
The Python dictionary get() method is used to retrieve the value corresponding to the specified key. This method accept keys and values, where value is optional. If the key is not found in the dictionary, but the value is specified, then this method
🌐
Google
developers.google.com › google for education › python › python dict and file
Python Dict and File | Python Education | Google for Developers
July 23, 2024 - Looking up a value which is not in the dict throws a KeyError -- use "in" to check if the key is in the dict, or use dict.get(key) which returns the value or None if the key is not present (or get(key, not-found) allows you to specify what value ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-the-first-key-in-dictionary
Get the First Key in Dictionary - Python - GeeksforGeeks
Python · d = {'harsh': 40, 'aryan': ... to the first key in the dictionary. We use a loop to iterate over the dictionary's keys, breaking after the first iteration to get the first key....
Published   July 12, 2025
🌐
Sentry
sentry.io › sentry answers › python › get key by value in dictionary python
Get key by value in dictionary Python | Sentry
If we just want the first key, we can access it with result[0]. This is an unusual way of using a dictionary, but may be necessary in certain circumstances.
🌐
Medium
medium.com › data-science › how-to-extract-key-from-python-dictionary-using-value-2b2f8dd2a995
How to Extract Key from Python Dictionary using Value | by Abhijith Chandradas | TDS Archive | Medium
September 20, 2021 - currency_dict is the dictionary ... 'GBP':'Pound', 'INR':'Rupee'} If you have the key, getting the value by simply adding the key within square brackets....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-values-of-particular-key-in-list-of-dictionaries
Get Values of Particular Key in List of Dictionaries - Python - GeeksforGeeks
July 12, 2025 - We use List comprehension to iterate over the list of dictionaries and retrieve the values associated with the particular key. If the key exists in the dictionary then the value will be appended to the result list. Python · li = [{'aryan': 10, 'harsh': 20}, {'aryan': 30, 'kunal': 40}, {'harsh': 50}] k = 'aryan' res = [d.get(k) for d in li if k in d] print(res) Output ·
🌐
W3Schools
w3schools.com › python › ref_dictionary_get.asp
Python Dictionary get() Method
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else · Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Matplotlib Intro Matplotlib Get Started Matplotlib Pyplot Matplotlib Plotting Matplotlib Markers Matplotlib Line Matplotlib Labels Matplotlib Grid Matplotlib Subplot Matplotlib Scatter Matplotlib Bars Matplotlib Histograms Matplotlib Pie Charts
🌐
Replit
replit.com › discover › how-to-get-the-key-of-a-dictionary-in-python
How to get the key of a dictionary in Python
April 13, 2026 - Build and deploy software collaboratively with the power of AI without spending a second on setup.