In Python versions before 3.7 dictionaries were inherently unordered, so what you're asking to do doesn't really make sense.

If you really, really know what you're doing, use

Copyvalue_at_index = list(dic.values())[index]

Bear in mind that prior to Python 3.7 adding or removing an element can potentially change the index of every other element.

Answer from NPE on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-key-index-in-dictionary
Key Index in Dictionary - Python - GeeksforGeeks
July 12, 2025 - This method converts the dictionary keys into a list and finds the index using .index(). It provides a concise solution but is less efficient due to list creation. Python · d = {'a': 10, 'b': 20, 'c': 30} k = 'b' try: i = list(d).index(k) print(i) except ValueError: print("Key not found") Output ·
Discussions

Can a tuple be used as a dictionary key?
Question This exercise says a key can be a hashable type like a number or string. Can a tuple be used as a dictionary key? Answer Yes, a tuple is a hashable value and can be used as a dictionary key. A tuple would be useful as a key when storing values associated with a grid or some other ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
9
August 9, 2018
How to get (first) element from list of dicts where dict key equals a specific value?
This will work: next(item["foo"] for item in my_dict if item["key"] == 3] Although if you're looking up several values this way, it will be more efficient to convert the whole thing to a simple dict of key to foo: better_dict = {item["key"]: item["foo"] for item in my_dict} Now you can just look up by key directly. More on reddit.com
🌐 r/learnpython
3
1
June 16, 2022
Is there a way to lookup a value in a dictionary?
Hello, guys! I just have a question about this. When saying if X in directions is it similar (or can be called an iteration through the dictionary)? Because if so, I see it works only if X is a key, not a value (regardless if that is a string or an integer): Is it possible to add an if condition ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
0
November 20, 2019
Using get() with nested dictionary.
When get misses, the default return is None, which can't itself be "get"ed. You could have get give a different miss, like a dictionary, which could then give you further misses. I might do that for a single layer, but with a bunch, I would probably do something like create a function to do the search for me, probably recursively. edit: some great ideas here: https://stackoverflow.com/questions/25833613/safe-method-to-get-value-of-nested-dictionary Having never had the chance to use reduce, I would 100% use one of those solutions. More on reddit.com
🌐 r/learnpython
9
5
April 10, 2024
🌐
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
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-65.php
Python: Access dictionary key’s element by index - w3resource
June 28, 2025 - Write a Python program to access dictionary key's element by index. ... num = {'physics': 80, 'math': 90, 'chemistry': 86} print(list(num)[0]) print(list(num)[1]) print(list(num)[2]) ... Write a Python program to move all occurrences of a specific number to the end of a list. Write a Python program to move all None values to the end of a list.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › get the index of key in python dictionary
Get the Index of Key in Python Dictionary - Spark By {Examples}
May 31, 2024 - Python provides various ways to get the index of the specified key of the dictionary. In dictionaries, elements are presented in the form
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair with del. If you store using a key that is already in use, the old value associated with that key is forgotten. Extracting a value for a non-existent key by subscripting (d[key]) raises a KeyError. To avoid getting this error when trying to access a possibly non-existent key, use the get() method instead, which returns None (or a specified default value) if the key is not in the dictionary.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-with-index-as-value
Python - Dictionary with Index as Value - GeeksforGeeks
July 11, 2025 - We can use a for loop with enumerate() to iterate over the list and store each element as a key with its index as value in a dictionary. This approach builds dictionary step by step without using comprehension.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-get-value-of-a-dictionary-given-by-index-of-maximum-value-of-given-key
Get Value of a Dictionary Given by index of Maximum Value of Given Key - GeeksforGeeks
July 23, 2025 - sorted(..., key=lambda x: x[1]) sorts by values: [(1, 4), (0, 6), (2, 9)]. [-1][0] gets the last (max value) tuple and extracts the index (2). d[opt_key][2] retrieves 2, which is our result. Comment · Article Tags: Article Tags: Python · Python Programs · Python dictionary-programs ·
🌐
Geek Python
geekpython.in › access-list-values-within-the-dictionary
How to Access List Values within the Dictionary in Python
August 15, 2023 - The convention dict_name[key][index] must be used to access the list values from the dictionary.
🌐
Edureka Community
edureka.co › home › community › categories › python › how to access the elements of a dictionary using...
How to access the elements of a dictionary using index | Edureka Community
July 4, 2019 - 51031/how-to-access-the-elements-of-a-dictionary-using-index ... How to access the elements of a dictionary using... Reading different format files from s3 having decoding issues using boto3 May 17, 2024 · What is the algorithm to find the sum of prime numbers in the input in python Feb 22, 2024
🌐
Quora
quora.com › How-do-you-select-python-tuple-dictionary-values-for-a-given-index-key
How to select python tuple/dictionary values for a given index/key - Quora
Answer: Syntactically you use the square brackets [code ][][/code] [code]value1 = my_list[7] value2= my_tuple[8] value3=my_dictionary[“9”] [/code]The first critical difference is a dictionary accessor — like the “9” in this example — can be any Python object that is hashable.
🌐
Leocon
leocon.dev › blog › 2021 › 08 › stop-accessing-dictionary-items-by-index
Stop Accessing dictionary items by index | Leonidas Constantinou
September 12, 2021 - You could also specify a different default value or even a callback. d = {'key1': 1, 'key2': 2} # Returns None d.get('new') # Returns 6 some_number = 6 d.get('new', some_number) def callback(): return 2 # Returns the function output d.get('new', callback())Copied to clipboard! Well, if you are still stubborn and still want to access your items by index, there is still a way. You can create your own version of the dictionary.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
Can a tuple be used as a dictionary key? - Python FAQ - Codecademy Forums
August 9, 2018 - Question This exercise says a key can be a hashable type like a number or string. Can a tuple be used as a dictionary key? Answer Yes, a tuple is a hashable value and can be used as a dictionary key. A tuple would be us…
🌐
Built In
builtin.com › software-engineering-perspectives › convert-list-to-dictionary-python
10 Ways to Convert Lists to Dictionaries in Python | Built In
Output order may vary, but keys and values are preserved. More on Python: 5 Ways to Remove Characters From a String in Python · By using enumerate(), we can convert a list into a dictionary with index as key and list item as the value.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.to_dict.html
pandas.DataFrame.to_dict — pandas 3.0.3 documentation
‘records’ : list like [{column -> value}, … , {column -> value}] ‘index’ : dict like {index -> {column -> value}}
🌐
TutorialsPoint
tutorialspoint.com › python-accessing-items-in-lists-within-dictionary
Python - Accessing Items in Lists Within Dictionary
August 14, 2023 - To access the values within a list, we need to use the square brackets "[]" notation and, specify the index of the elements we want to retrieve. The index starts from 0 for the first element and increments by one for each subsequent element.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
Is there a way to lookup a value in a dictionary? - Python FAQ - Codecademy Forums
November 20, 2019 - Hello, guys! I just have a question about this. When saying if X in directions is it similar (or can be called an iteration through the dictionary)? Because if so, I see it works only if X is a key, not a value (rega…
🌐
Quora
quora.com › How-do-I-fetch-only-few-values-from-a-Python-dictionary-and-get-only-those-keys
How to fetch only few values from a Python dictionary and get only those keys - Quora
I think you don’t get to know about python… In dictionary keys are distinct and values are pointing to the keys. For example, If you have some values in your hand and want to search for the key of that value can be done but the values of different keys may be initialized same and will return one or more keys for same value. ... With this code you can search the key of the value by changing the vals[index...
🌐
Reddit
reddit.com › r/learnpython › using get() with nested dictionary.
r/learnpython on Reddit: Using get() with nested dictionary.
April 10, 2024 -

Hey all, hoping someone can help me out. I'm new to python but getting the hang of it. I'm using subprocess to run ffprobe and have it return JSON. Depending on the file I'm analyzing, some properties may not exist and won't appear in the JSON results. If i print this it works:

dvd_properties['streams'][0]['duration']

But I'm having trouble using the get() method on it:

dvd_properties.get('streams').get('0').get('duration'), "Unknown"

I'm trying to use get() so I have a default value if there are no results in the JSON output. I'm testing on a file that does have the duration element to make sure it works if I have data.

Can anyone lend me a hand? I've tried to search but I can't find anything about this particular situation. I have the get('parent').get('child') working for simple cases, so I'm hoping it will work here as well and I'm just missing something obvious.

Thanks in advance, I do appreciate it.