This will convert the dict_keys object to a list:

Copylist(newdict.keys())

On the other hand, you should ask yourself whether or not it matters. It is Pythonic to assume duck typing -- if it looks like a duck and it quacks like a duck, it is a duck. The dict_keys object can be iterated over just like a list. For instance:

Copyfor key in newdict.keys():
    print(key)

Note that dict_keys doesn't support insertion newdict[k] = v, though you may not need it.

Answer from Chris on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_dictionary_keys.asp
Python Dictionary keys() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.keys() print(x) Try it Yourself »
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-keys-method
Python Dictionary keys() method - GeeksforGeeks
3 weeks ago - dict.keys() method in Python returns a view object that contains all the keys of the dictionary. The returned object is dynamic, meaning any changes made to the dictionary are automatically reflected in the view.
Discussions

How do I return dictionary keys as a list in Python? - Stack Overflow
On the other hand, you should ask yourself whether or not it matters. It is Pythonic to assume duck typing -- if it looks like a duck and it quacks like a duck, it is a duck. The dict_keys object can be iterated over just like a list. More on stackoverflow.com
🌐 stackoverflow.com
Python dictionary keys() Method - Stack Overflow
I can understand indices1 work well because (0, 'cat')is one of the keys, but why indices turn out the same result? Any hint will be appreciated. BTW, for large data set, indices's performance is way much better than indices1. ... Save this answer. ... Show activity on this post. On python2.x, ... More on stackoverflow.com
🌐 stackoverflow.com
list - Understanding accessing the key and value in dictionaries Python - Stack Overflow
This is consistent with the check key in my_dict, which tests whether key is present in my_dict. ... This also means you can get the list of countries in your use case simply by countries = list(golds). ... Save this answer. ... Show activity on this post. ... The Python creators had to choose ... More on stackoverflow.com
🌐 stackoverflow.com
Python dictionary keys "new" syntax
You can use any hashable value as a key. It’s not a matter of syntax. More on reddit.com
🌐 r/learnpython
31
0
January 17, 2026
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
Another useful data type built into Python is the dictionary (see Mapping Types — dict). Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys.
Top answer
1 of 13
1721

This will convert the dict_keys object to a list:

Copylist(newdict.keys())

On the other hand, you should ask yourself whether or not it matters. It is Pythonic to assume duck typing -- if it looks like a duck and it quacks like a duck, it is a duck. The dict_keys object can be iterated over just like a list. For instance:

Copyfor key in newdict.keys():
    print(key)

Note that dict_keys doesn't support insertion newdict[k] = v, though you may not need it.

2 of 13
557

Python >= 3.5 alternative: unpack into a list literal [*newdict]

New unpacking generalizations (PEP 448) were introduced with Python 3.5 allowing you to now easily do:

Copy>>> newdict = {1:0, 2:0, 3:0}
>>> [*newdict]
[1, 2, 3]

Unpacking with * works with any object that is iterable and, since dictionaries return their keys when iterated through, you can easily create a list by using it within a list literal.

Adding .keys() i.e [*newdict.keys()] might help in making your intent a bit more explicit though it will cost you a function look-up and invocation. (which, in all honesty, isn't something you should really be worried about).

The *iterable syntax is similar to doing list(iterable) and its behaviour was initially documented in the Calls section of the Python Reference manual. With PEP 448 the restriction on where *iterable could appear was loosened allowing it to also be placed in list, set and tuple literals, the reference manual on Expression lists was also updated to state this.


Though equivalent to list(newdict) with the difference that it's faster (at least for small dictionaries) because no function call is actually performed:

Copy%timeit [*newdict]
1000000 loops, best of 3: 249 ns per loop

%timeit list(newdict)
1000000 loops, best of 3: 508 ns per loop

%timeit [k for k in newdict]
1000000 loops, best of 3: 574 ns per loop

with larger dictionaries the speed is pretty much the same (the overhead of iterating through a large collection trumps the small cost of a function call).


In a similar fashion, you can create tuples and sets of dictionary keys:

Copy>>> *newdict,
(1, 2, 3)
>>> {*newdict}
{1, 2, 3}

beware of the trailing comma in the tuple case!

🌐
Career Karma
careerkarma.com › blog › python › python dictionary keys: a complete guide
Python Dictionary Keys: A Complete Guide: A Complete Guide | Career Karma
December 1, 2023 - The Python dictionary keys() method returns an object which contains the keys in a dictionary. You can use the list() method to convert the object into a list.
🌐
Analytics Vidhya
analyticsvidhya.com › home › what is python dictionary keys() method?
What is Python Dictionary keys() Method? - Analytics Vidhya
January 31, 2024 - When it comes to performance, the keys() method is the most efficient way to retrieve dictionary keys as a list. It provides a view object that directly references the keys of the dictionary, without creating a new list.
Find elsewhere
🌐
Google
developers.google.com › google for education › python › python dict and file
Python Dict and File | Python Education | Google for Developers
Looking up or setting a value in a dict uses square brackets, e.g. dict['foo'] looks up the value under the key 'foo'. Strings, numbers, and tuples work as keys, and any type can be a value. Other types may or may not work correctly as keys (strings and tuples work cleanly since they are immutable).
🌐
Sololearn
sololearn.com › en › Discuss › 1462669 › what-is-a-key-in-python-dictionaries
What is a Key in Python Dictionaries?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Medium
medium.com › the-pythonworld › still-checking-for-keys-in-python-dictionaries-heres-the-smarter-way-bd2d92618a5a
Still Checking for Keys in Python Dictionaries? Here’s the Smarter Way | by Aashish Kumar | The Pythonworld | Medium
October 7, 2025 - Out of frustration, at times you need to try a direct lookup and process missing keys differently. Rather than coding if key in dict, simply follow the EAFP principle of Python — Easier to Ask for Forgiveness than Permission:
Top answer
1 of 3
4

On python2.x, dict.keys is (IMHO) more or less worthless. You can iterate over a dictionary's keys directly:

for key in d:
    ...

which will be more efficient than iterating over the keys:

for key in d.keys():
    ...

which makes a separate list, and then iterates over it -- effectively doing the iteration twice + a bunch of extra memory overhead of having a throw-away list, etc, etc.


Your use-case is actually doing a membership test on the keys. It's the difference between:

x in some_list  # is "x" an item in the list?

and

x in some_dict  # is "x" a key in the dictionary?

Membership tests on list objects are O(N) but on dict are O(1). So, for every "turn" of the loop, you're doing an O(N) list construction and an O(N) lookup to see if the item is in the list instead of a simple O(1) hash lookup of the key.

It should be noted If you ever do actually need a list of a dictionary's keys, you could get it easily1:

list(d)

Fortunately, python3.x has taken steps in the correct direction. d.keys() returns a set-like object in python3.x. You can use this to efficiently calculate the intersection of two dictionaries' keys for example which can be useful in some situations.

It's also worth pointing out that the set like object in python3.x (called a dict_keys object) also has O(1) membership testing (as is to be expected of something that looks like a set), compared to the O(n) membership test of a list.

1This, consequentially, works in python2.x and python3.x so it's a nice thing to remember when you're trying to write code that is compatible with either...

2 of 3
0

Both refers (iterate over) the dictionary keys only.

for i in dic:

is equal to

for i in dic.keys():
🌐
Tutorialspoint
tutorialspoint.com › python › dictionary_keys.htm
Python dictionary keys() Method
The Python dictionary keys() method is used to retrieve the list of all the keys in the dictionary. In Python, a dictionary is a set of key-value pairs. These are also referred to as "mappings" since they "map" or "associate" the key objects with
Top answer
1 of 3
3

To loop over the keys you do:

Copyfor k in golds.keys():

For the values:

Copyfor v in golds.values():

And for both:

Copyfor k, v in golds.items():

The Python creators had to choose one of the above to be the default experience when doing for item in golds. They decided upon the first one.


But why?

As the Sven and Amitai have pointed out, making it the default behavior to iterate over the keys is consistent with the ability to do key in my_dict. The more I think about it, value in my_dict would have just been a bad idea.

Also, I think Python wanted to be consistent with the way many other languages handled the situation at that time, so that brings up the question, which major language was the first one to loop over dictionaries? I tried to do some research to figure this out, but I couldn't find out which language was the first to make this choice :(

2 of 3
1

When iterating of a dictionary, you will be iterating over the keys only. Your piece of code:

Copyfor item in golds:
    countries.append(item)

does just that.

A much simpler way of doing this would be simply:

Copycountries = list(golds)

because the list constructor iterates over a sequence, and in the case of a dict, that means its keys. While the above works, it is a bit obscure. A better options would be:

Copycountries = list(golds.keys())

The keys method returns a sequence (iterator in Python 3, simply a list in Python 2) of all the dictionary keys. This is better (IMHO) than the previous method, because it clearly states the intent of the code, making it more readable.

🌐
Programiz
programiz.com › python-programming › methods › dictionary › keys
Python Dictionary keys() (With Examples)
The keys() method extracts the keys of the dictionary and returns the list of keys as a view object. In this tutorial, you will learn about the Python Dictionary keys() method with the help of examples.
🌐
Codecademy
codecademy.com › learn › dacp-python-fundamentals › modules › dscp-python-dictionaries › cheatsheet
Python Fundamentals: Python Dictionaries Cheatsheet | Codecademy
It contains data as a set of key: value pairs. my_dictionary = {1: "L.A. Lakers", 2: "Houston Rockets"} ... When trying to look at the information in a Python dictionary, there are multiple methods that return objects that contain the dictionary keys and values.
🌐
YouTube
youtube.com › watch
Python Dictionaries Explained | Key-Value Pairs, Methods & Real-World Usage - YouTube
Dictionaries are powerful! Learn to use Python's most flexible data structure.✅ Dictionary creation and syntax✅ Accessing and modifying values✅ Dictionary me...
Published   March 3, 2026
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-key-index-in-dictionary
Key Index in Dictionary - Python - GeeksforGeeks
July 12, 2025 - list(d) creates a list of dictionary keys and .index(k) finds the index of k in the list. try-except handles cases where k is not in the dictionary. Comment · Article Tags: Article Tags: Python · Python Programs · Python dictionary-programs · Python Fundamentals ·
🌐
Python Helper
pythonhelper.com › home › python dict keys() method
Python Dict keys(Access, Modify, Merge, Convert) Items
August 7, 2023 - Python dict keys() acts as a key detector, allowing you to access all keys in a dictionary. It returns a view object that provides a dynamic view of the keys.
🌐
OpenAI
platform.openai.com
OpenAI Platform
We cannot provide a description for this page right now