List All Keys and Values

Easy ⏱ 8 min 88% acceptance ★★★★★ 4.8
Write a function keys_and_values(d) that returns a tuple (keys_list, values_list) where keys_list is a list of d's keys and values_list is a list of d's values, both in the dict's natural iteration order.

Examples

Example 1
Input
keys_and_values({'a': 1, 'b': 2})
Output
(['a', 'b'], [1, 2])
Explanation

keys() and values() converted to lists, same order.

Constraints

  • Order must match the dict's own iteration order.

Topics

Dictionarieskeys()/values()

Companies

GoogleCapgemini

Hints

Hint 1

`list(d.keys())` and `list(d.values())`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.