← Back to challenges

Convert Key, Values in a Dictionary to List

PythonHardobjectsarrays

Instructions

Write a function that converts a dictionary into a list of keys-values tuples.

Examples

dict_to_list({
  "D": 1,
  "B": 2,
  "C": 3
}) ➞ [("B", 2), ("C", 3), ("D", 1)]

dict_to_list({
  "likes": 2,
  "dislikes": 3,
  "followers": 10
}) ➞ [("dislikes", 3), ("followers", 10), ("likes", 2)]

Notes

Return the elements in the list in alphabetical order.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Return Odd > Even