0

Bubble sort but according to index

This is the code for bubble sorting but instead of the numbers themselves i want the indexes to be sorted instead, the code doesnt really crash but i dont get what i want printed out instead <built-in method index of list…..> is shown https://code.sololearn.com/caVcYEAMJVzv/?ref=app

28th Feb 2022, 12:02 AM
Lenoname
5 Antworten
+ 2
To know where it the value was prior to sort you will have to make a copy of the list. Index method will not work with int in python but there is another method using numpy called where. https://code.sololearn.com/cwdg19Dd9Tfo I think this is what you trying to do.
28th Feb 2022, 1:12 AM
William Owens
William Owens - avatar
+ 2
Lenoname Here's a core python way of doing what you're asking. Just added a bit to your sort function. https://code.sololearn.com/cAl8HFMGkN03/?ref=app
28th Feb 2022, 1:28 AM
ChaoticDawg
ChaoticDawg - avatar
0
I am not sure what you are trying to do with index: My understanding of index: colors = ['red', 'green', 'blue'] print(colors.index('green')) output: 1
28th Feb 2022, 12:12 AM
William Owens
William Owens - avatar
0
William Owens List1 = [3,5,4,2] Sorted : [2,3,4,5] Sorted according to position:[[3],[0],[2],[1]] Index number [3] means 2 ,[0] means 3,[2] means 4, [1] is 5
28th Feb 2022, 12:26 AM
Lenoname
0
ChaoticDawg much better solution.
28th Feb 2022, 1:40 AM
William Owens
William Owens - avatar