About 50 results
Open links in new tab
  1. Accessing dict_keys element by index in Python3 - Stack Overflow

    In Python 3, the dict.keys() method returns a dictionary view object, which acts as a set. Iterating over the dictionary directly also yields keys, so turning a dictionary into a list results in a list of all the keys:

  2. How do I return dictionary keys as a list in Python?

    With Python 2.7, I can get dictionary keys, values, or items as a list:

  3. python - Iterating over a dictionary using a 'for' loop, getting keys ...

    Mar 16, 2017 · In Python 3, the iteration has to be over an explicit copy of the keys (otherwise it throws a RuntimeError) because my_dict.keys() returns a view of the dictionary keys, so any change to …

  4. python - Filter dict to contain only certain keys? - Stack Overflow

    Aug 6, 2010 · dict_you_want = {key: old_dict[key] for key in your_keys} Uses dictionary comprehension. If you use a version which lacks them (ie Python 2.6 and earlier), make it dict((key, old_dict[key]) for …

  5. python - Why use dict.keys? - Stack Overflow

    Jul 14, 2013 · In Python 3, dct.keys() returns a "dictionary view object", so if you need to get a hold of an unmaterialized view to the keys (which could be useful for huge dictionaries) outside of a for loop …

  6. python - How do I sort a dictionary by key? - Stack Overflow

    Jan 26, 2017 · From python 3.7.4 manual: "Performing list (d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order". So insertion order is something which is preserved and we …

  7. python - Rename a dictionary key - Stack Overflow

    May 10, 2013 · Is target_dict.keys() guaranteed to be the same order as in definition? I thought a Python dict is unordered, and the order from a dict's keys view is unpredictable

  8. python - Why do `key in dict` and `key in dict.keys ()` have the same ...

    Mar 28, 2015 · (emphasis mine; dictionaries in Python are mapping objects) In Python 3, the has_key method was removed altogether and now there the correct way to test for the existence of a key is …

  9. Difference between list (dict) and dict.keys ()? - Stack Overflow

    Aug 5, 2015 · In Python 3, the dict_keys object returned by .keys() is just pointing to the actual dictionary keys (and changes when the dictionary is changed), while the list command creates a copy of the keys.

  10. python - Can I create a dictionary with integer keys using dict ...

    Sep 12, 2017 · Can I create a dictionary with integer keys using dict ()? Ask Question Asked 10 years, 6 months ago Modified 1 month ago