Q. Write a program that sorts an array of integer in ascending order. What if, you need to sort element of a tuple? Is it possible? How can you make it happen?
Answer :-
Yes, It is possible by some modification in program.
Program :-
tup = eval (input ("Enter Tuple :- ")) lst = [] for i in tup : lst += [i] lst.sort() newtup = tuple(lst) print ("Sorted Tuple :- ", newtup)
Output :-
Enter Tuple :- (9,3,5,6,2,0,1,4,7)
Sorted Tuple :- (0, 1, 2, 3, 4, 5, 6, 7, 9)
>>>
Enter Tuple :- (45,98,32,45,75,98,123,543,8)
Sorted Tuple :- (8, 32, 45, 45, 75, 98, 98, 123, 543)
>>>
Sorted Tuple :- (0, 1, 2, 3, 4, 5, 6, 7, 9)
>>>
Enter Tuple :- (45,98,32,45,75,98,123,543,8)
Sorted Tuple :- (8, 32, 45, 45, 75, 98, 98, 123, 543)
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )