This will convert the dict_keys
object to a list
:
list(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:
for key in newdict.keys():
print(key)
Note that dict_keys
doesn’t support insertion newdict[k] = v
, though you may not need it.
Related Contents:
- Finding median of list in Python
- Appending to list in Python dictionary [duplicate]
- One liner: creating a dictionary from list with indices as keys
- How to add an element to the beginning of an OrderedDict?
- How do I return dictionary keys as a list in Python?
- How do I sort a list of dictionaries by a value of the dictionary?
- What is the difference between dict.items() and dict.iteritems() in Python2?
- Are dictionaries ordered in Python 3.6+?
- Getting a list of values from a list of dicts
- Converting Dictionary to List? [duplicate]
- Python 3 turn range to a list
- Remove duplicate dict in list in Python
- Django TemplateDoesNotExist?
- Create a list with initial capacity in Python
- Are lists thread-safe?
- What is `1..__truediv__` ? Does Python have a .. (“dot dot”) notation syntax?
- Accessing dict_keys element by index in Python3
- Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
- What causes [*a] to overallocate?
- Iterating Over Dictionary Key Values Corresponding to List in Python
- How to convert list of key-value tuples into dictionary?
- enumerate() for dictionary in Python
- How to find the min/max value of a common key in a list of dicts?
- How can I initialize a dictionary of distinct empty lists in Python?
- String formatting in Python 3
- How do I combine two lists into a dictionary in Python? [duplicate]
- python filter list of dictionaries based on key value
- How to create a Python dictionary with double quotes as default quote format?
- Appending a dictionary to a list – I see a pointer like behavior
- NLTK python error: “TypeError: ‘dict_keys’ object is not subscriptable”
- What is the purpose of collections.ChainMap?
- Why is a list comprehension so much faster than appending to a list?
- How do I serialize a Python dictionary into a string, and then back to a dictionary?
- Why does b+=(4,) work and b = b + (4,) doesn’t work when b is a list?
- How do I initialize a dictionary of empty lists in Python?
- How can I avoid “RuntimeError: dictionary changed size during iteration” error?
- Size of a Python list in memory
- list to dictionary conversion with multiple values per key?
- Iterate through dictionary values?
- Changing values of a list of namedtuples
- Grouping Python dictionary keys as a list and create a new dictionary with this list as a value
- How to sort a list of dictionaries by a value of the dictionary in Python?
- How to extend/concatenate two iterators in Python [duplicate]
- Union of multiple sets in python
- Sorting a dictionary with lists as values, according to an element from the list
- Setting a value in a nested Python dictionary given a list of indices and value
- Use of input/raw_input in python 2 and 3 [duplicate]
- How to iterate through a list of dictionaries
- Iterating over dictionary items(), values(), keys() in Python 3
- Python: Difference between kwargs.pop() and kwargs.get()