Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
22 lines (18 loc) · 468 Bytes

dict-to-list.md

File metadata and controls

22 lines (18 loc) · 468 Bytes
title type tags cover dateModified
Dictionary to list
snippet
dictionary
list
new-york
2020-11-02 19:27:53 +0200

Converts a dictionary to a list of tuples.

  • Use dict.items() and list() to get a list of tuples from the given dictionary.
def dict_to_list(d):
  return list(d.items())
d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}
dict_to_list(d)
# [('one', 1), ('three', 3), ('five', 5), ('two', 2), ('four', 4)]