1. Dictionary (dict)
dict = {‘name’: ‘Zara’, ‘age’: 7, ‘class’: ‘First’}
1.1 Dictionary---Strings
print (type(str(dict)), str(dict))
The results are as follows
<class ‘str‘> {‘name‘: ‘Zara‘, ‘age‘: 7, ‘class‘: ‘First‘}
1.2 Dictionary---Tuples
print(tuple(dict))
The results are as follows
(‘age’, ‘name’, ‘class’)
1.3 Dictionary---Tuples
print(tuple(dict.values()))
The results are as follows
(7, ‘Zara’, ‘First’)
1.4 Dictionary---List
print(list(dict))
The results are as follows
[‘age’, ‘name’, ‘class’]
1.5 Dictionary---List
print(dict.values())
The results are as follows
dict_values([‘Zara‘, 7, ‘First‘])
2. Tuples (turple)
tup = (1,2,3,4,5)
2.1 Tuples---strings
print(tup.__str__())
The results are as follows
(1,2,3,4,5)
2.2 Tuples---List
The results are as follows
[1,2,3,4,5]
2.3 tuples cannot be converted to dictionaries 3. List
nums=[1, 3, 5, 7, 8, 13, 20]
3.1 List---Strings
print(str(nums))
The results are as follows
[1, 3, 5, 7, 8, 13, 20]
3.2 List---tuples
tuple(nums)
The results are as follows
(1, 3, 5, 7, 8, 13, 20)
2.3 list cannot be converted to Dictionary 4. String 4.1 String---List
print(list(eval("(1,2,3)")))
The results are as follows
[1,2,3]
4.2 String---Tuples
tuple(eval("(1,2,3)"))
The results are as follows
(1,2,3)
4.3 String---Dictionary
print (type(eval("{‘name‘:‘ljq‘, ‘age‘:24}")))
The results are as follows
<class ‘dict‘>
Turple list Dict convert to and from each other