Python program to create one list from set and dictionary

Introduction :

In this quick python tutorial, we will learn how to create one list from one set or dictionary. A set can keep only unique elements and dictionary holds key-value pairs.

We can convert one dictionary or set to a list in python easily.

Let me show you how :

Python program :

Below is the program :

given_set = {1, 2, 3, 4, 5}
given_dict = {1: 'one', 2: 'two', 3: 'three', 4: 'four',5: 'five'}

print(list(given_set))
print(list(given_dict))

Output :

This program will print the below output :

[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]

Here, given_set is a set and given_dict is a dictionary. Using list constructor will convert it to a list.

Similar tutorials :