Write a program to find Maximum and Minimum K elements in Tuple


Topic: Write a program to find Maximum and Minimum K elements in Tuple

Solution

test_tup = (5, 20, 3, 7, 6, 8) 
print("The original tuple is : " + str(test_tup)) 
K = 2
test_tup = list(test_tup) 
temp = sorted(test_tup) 
res = tuple(temp[:K] + temp[-K:]) 
print("The extracted values : " + str(res))  



List all Python Programs