How to covert list, tuple, sets and dictionaries into each other ?

Kindly tell methods to covert list, tuple, sets and dictionaries into each other. For ex How can we convert sets into tuple, list and dictionaries

Hi chinmay

There are builtin functions such as tuple(), list(), dict(), set().

For example :


nums = [1,2,3,4]

print(nums,type(nums))  # output :[1, 2, 3, 4] <class 'list'>


nums_set = set(nums)
# here list of elements are converted into set of elements remember set doesnot contain duplicates.

print(nums_set,type(nums_set)) # output : {1, 2, 3, 4} <class 'set'>



num_ele = [(1,2),(3,4),(5,6)] 
num_dict = dict(num_ele)
# Dictionary contain key value pairs so we should provide the pair of values or else we can convert into dictionary.

print(,type(dict(num_ele)))# output : {1: 2, 3: 4, 5: 6} <class 'dict'>

Please go through the code and try for tuple() yourself and let us know if you understood of to convert a list into a tuple and set it into tuple and vice-versa.

Thank you