Q. Write a program that sort a list of tuple – elements in descending order of points using bubble sort. The tuple – element of the list contain following information about different players:

(player number , player name , points )


You can understand by Watching video :-



Answer :-

lst = [(103 , 'Path' , 3001),(104 ,'Walla',2819),(101,'Portal',3451),(105,'Express',2971)]
for i in range( len( lst ) - 1 ):
    for j in range( len ( lst ) - 1 ):
        if lst [ j ] [ 2 ] < lst [ j + 1 ] [ 2 ] :
            lst [ j ] , lst [ j + 1 ] = lst [ j + 1 ] , lst [ j ]
print(lst)

Output :-

[(101, 'Portal', 3451), (103, 'Path', 3001), (105, 'Express', 2971), (104, 'Walla', 2819)]
>>> 


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post