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
🌐
Bobby Hadz
bobbyhadz.com β€Ί blog β€Ί python-get-position-of-key-in-dictionary
How to access a Dictionary Key by Index in Python | bobbyhadz
Copied!from collections import OrderedDict my_dict = OrderedDict( [('id', 1), ('name', 'Bobbyhadz'), ('age', 30)] ) key = list(my_dict)[1] print(key) # πŸ‘‰οΈ name value = list(my_dict.values())[1] print(value) # πŸ‘‰οΈ Bobbyhadz index = None ...
Discussions

Get the index of the values in python dict
say I have this dict with the values and I want to get the index of each element of the values for either key. I have tried different things but nothing has worked yet. Any help my_dict = { "Up": [1,2,3,4], "Dow… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
4
0
April 30, 2021
python - how to get access elements of a dictionary by its index? - Stack Overflow
Your example shows accessing all values of the dict. Is that actually what you want in practice? ... Save this answer. ... Show activity on this post. You need to convert the keys of the dictionary to a list in order to access by its index. More on stackoverflow.com
🌐 stackoverflow.com
python - How to get the index with the key in a dictionary? - Stack Overflow
I have the key of a python dictionary and I want to get the corresponding index in the dictionary. Suppose I have the following dictionary, d = { 'a': 10, 'b': 20, 'c': 30} Is there a combination of More on stackoverflow.com
🌐 stackoverflow.com
python - How to index into a dictionary? - Stack Overflow
Dictionaries are unordered in Python versions up to and including Python 3.6. If you do not care about the order of the entries and want to access the keys or values by index anyway, you can create a list of keys for a dictionary d using keys = list(d), and then access keys in the list by index ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
🌐
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 - ... 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.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί get-index-of-values-in-python-dictionary
Get Index of Values in Python Dictionary - GeeksforGeeks
July 23, 2025 - For example, consider the following dictionary: a = {1: [1, 2], 2: [3, 4, 6]} here for each list stored as a value we want to retrieve the indices of its elements then the expected output for the example above is: [[0, 1], [0, 1, 2]]
🌐
Delft Stack
delftstack.com β€Ί home β€Ί howto β€Ί python β€Ί python dictionary index
Python Dictionary Index | Delft Stack
March 11, 2025 - This tutorial demonstrates how to index and access elements from a dictionary using their index in Python. Learn effective methods to retrieve values, including direct key access, the get() method, and iteration techniques. Enhance your Python skills with practical examples and clear explanations on managing dictionary data efficiently.
🌐
Finxter
blog.finxter.com β€Ί home β€Ί learn python blog β€Ί how to access a dictionary key by index
How to Access a Dictionary Key by Index - Be on the Right Side of Change
May 10, 2022 - Then the appropriate key is accessed based on the scenario above. staff = {'Amy': 23, 'Ben': 32, 'Micah': 37, 'Jon': 19, 'Karn': 39} names = list(staff) print(names[3]) This code declares a Dictionary containing five (5) key:value pairs and saves them to staff.
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org β€Ί python
Get the index of the values in python dict - Python - The freeCodeCamp Forum
April 30, 2021 - Any help my_dict = { "Up": [1,2,3,4], "Down": [5,6] } I tried this indx_val= [[y for y in x] for x in my_dict.values() if my_dict.keys() == "Up"] Edit I tried this too: my_keys = ' '.join([key for key in my_dict]) indx_val= [[y for y in x] for ...
🌐
Tutorial Reference
tutorialreference.com β€Ί python β€Ί examples β€Ί faq β€Ί python-how-to-access-a-dictionary-by-index
How to Access Dictionary Keys and Values by Index in Python | Tutorial Reference
To get both the key and value at a specific position, convert the dictionary's items to a list: ... key, value = ...[index] unpacks the tuple at the specified index into separate key and value variables. To find all keys associated with a specific value, use a list comprehension: ... In versions ...
🌐
Python Guides
pythonguides.com β€Ί python-dictionary-index
Find the Index of Items in a Python Dictionary
May 23, 2024 - # Dictionary of employees with their IDs as keys and names as values employees = { 'E001': 'James', 'E002': 'Bobby', 'E003': 'Charles', 'E004': 'Vincent' } # Initialize an index counter to 0 index = 0 # Iterate over the keys (employee IDs) in ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-dictionary-with-index-as-value
Python - Dictionary with Index as Value - GeeksforGeeks
July 11, 2025 - For example, a = ['a', 'b', 'c', 'd'] we need to find index of each elements in list so that output should be {'a': 0, 'b': 1, 'c': 2, 'd': 3}. We can use dictionary comprehension to create a dictionary where each element of a list is mapped ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί 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
February 6, 2025 - For example: d = {β€œa”: [3, 8, 2], β€œb”: [5, 1, 7], β€œc”: [6, 4, 9]} , max_search = β€œc” and opt_key = β€œa” then output will be 2 as the maximum value in key β€œc” is 9, which is at index 2 and the value at index 2 in key β€œa” ...
🌐
Iditect
iditect.com β€Ί faq β€Ί python β€Ί accessing-dictionary-value-by-index-in-python.html
Accessing dictionary value by index in python
# Example: Access dictionary value by converting values to a list and indexing my_dict = {'a': 1, 'b': 2, 'c': 3} value_at_index_2 = list(my_dict.values())[2] "Python dictionary get value by index" Description: This query seeks ways to retrieve dictionary values by their index position in Python.
🌐
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
🌐
TutorialsPoint
tutorialspoint.com β€Ί dictionary-with-index-as-value-in-python
Dictionary with index as value in Python
We can use it with dictionary comprehension to create a dictionary where list values become keys and their positions become values ? days = ['Mon', 'Tue', 'Wed', 'Wed', 11, 11] # Given list print("Given list:", days) # Converting to Dictionary new_dict = {val: key + 1 for key, val in enumerate(days)} # Print result print("Dictionary created with index:", new_dict)
Top answer
1 of 11
254

If anybody is still looking at this question, the currently accepted answer is now outdated:

Since Python 3.7*, dictionaries are order-preserving, that is they now behave like collections.OrderedDicts. Unfortunately, there is still no dedicated method to index into keys() / values() of the dictionary, so getting the first key / value in the dictionary can be done as

Copyfirst_key = list(colors)[0]
first_val = list(colors.values())[0]

or alternatively (this avoids instantiating the keys view into a list):

Copydef get_first_key(dictionary):
    for key in dictionary:
        return key
    raise IndexError

first_key = get_first_key(colors)
first_val = colors[first_key]

If you need an n-th key, then similarly

Copydef get_nth_key(dictionary, n=0):
    if n < 0:
        n += len(dictionary)
    for i, key in enumerate(dictionary.keys()):
        if i == n:
            return key
    raise IndexError("dictionary index out of range") 

* CPython 3.6 already included insertion-ordered dicts, but this was only an implementation detail. The language specification includes insertion-ordered dicts from 3.7 onwards.

2 of 11
137

Dictionaries are unordered in Python versions up to and including Python 3.6. If you do not care about the order of the entries and want to access the keys or values by index anyway, you can create a list of keys for a dictionary d using keys = list(d), and then access keys in the list by index keys[i], and the associated values with d[keys[i]].

If you do care about the order of the entries, starting with Python 2.7 you can use collections.OrderedDict. Or use a list of pairs

Copyl = [("blue", "5"), ("red", "6"), ("yellow", "8")]

if you don't need access by key. (Why are your numbers strings by the way?)

In Python 3.7, normal dictionaries are ordered, so you don't need to use OrderedDict anymore (but you still can – it's basically the same type). The CPython implementation of Python 3.6 already included that change, but since it's not part of the language specification, you can't rely on it in Python 3.6.

🌐
Cisco
ipcisco.com β€Ί home β€Ί python dictionary access
Python Dictionary Access | Index Method | Get Method ⋆
March 5, 2026 - We can get the same result with get() method. character = { "race": "wizard", "name": "Gandalf", "color": "grey" } print(character.get("name")) ... These are the methods used to access any value of a key:value pair.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-key-index-in-dictionary
Key Index in Dictionary - Python - GeeksforGeeks
February 11, 2025 - Method 1: Using index We can get the particular tuples by using an index: Syntax: dictionary_name[index] To iterate the entire tuple values in a particular index for i in range(0, len(dictionary_name[index])): print ...