Dictionary keys

Python, Dictionary, List · Nov 2, 2020

Creates a flat list of all the keys in a flat dictionary.

  • Use dict.keys() to return the keys in the given dictionary.
  • Return a list() of the previous result.
def keys_only(flat_dict):
  return list(flat_dict.keys())
ages = {
  'Peter': 10,
  'Isabel': 11,
  'Anna': 9,
}
keys_only(ages) # ['Peter', 'Isabel', 'Anna']

More like this

  • Combine dictionary values

    Combines two or more dictionaries, creating a list of values for each key.

    Python, Dictionary · Apr 4, 2021

  • Get nested value

    Retrieves the value of the nested key indicated by the given selector list from a dictionary or list.

    Python, Dictionary · Oct 28, 2020

  • Map dictionary values

    Creates a dictionary with the same keys as the provided dictionary and values generated by running the provided function for each value.

    Python, Dictionary · Nov 2, 2020