lst = [('for', 3), ('python', 9), ('engineers', 10)]
print("The original list is : " + str(lst))
ord_list = ['python', 'for', 'engineers']
temp = dict(lst)
res = [(key, temp[key]) for key in ord_list]
print("The ordered tuple list : " + str(res))
Solve Problems by Coding Solutions - A Complete solution for python programming
lst = [('for', 3), ('python', 9), ('engineers', 10)]
print("The original list is : " + str(lst))
ord_list = ['python', 'for', 'engineers']
temp = dict(lst)
res = [(key, temp[key]) for key in ord_list]
print("The ordered tuple list : " + str(res))
test_list = [(4, 5, 9), (-3, 2, 3), (-3, 5, 6), (4, 6)]
print("The original list is : " + str(test_list))
res = [sub for sub in test_list if all(ele >= 0 for ele in sub)]
print("Positive elements Tuples : " + str(res))
sample_tuple = ((4, 'Gfg', 10), (3, 'is', 8), (6, 'Best', 10))
print("The original tuple : " + str(sample_tuple))
res = [{'key': sub[0], 'value': sub[1], 'id': sub[2]} for sub in sample_tuple]
print("The converted dictionary : " + str(res))
def Sort_Tuple(tup):
lst = len(tup)
for i in range(0, lst):
for j in range(0, lst-i-1):
if (tup[j][1] > tup[j + 1][1]):
temp = tup[j]
tup[j]= tup[j + 1]
tup[j + 1]= temp
return tup
tup =[('for', 24), ('for', 10), ('programming', 28),
('python', 5), ('solution', 20), ('engineers', 15)]
print(Sort_Tuple(tup))