make list of tuples python code example
Example 1: list of tuple to tuple of list python
>>> source_list = [('1','a'),('2','b'),('3','c'),('4','d')]
>>> list1, list2 = zip(*source_list)
>>> list1
('1', '2', '3', '4')
>>> list2
('a', 'b', 'c', 'd')
Example 2: python list of tuples
list_tuples = [('Nagendra',18),('Nitesh',28),('Sathya',29)]
for name,age in list_tuples:
print(name,age)
for index,(name,age) in list_tuples:
print(f'My name is {name} and age is {age} and index is {index}')
print('My name is {n} and age is {a} and index is {i}'.format(n=name,a=age,i=index))