Given a list:
It's a shame I cannot use dict or set to help with this problem. No libraries import either sadly.
lst = [48,52,35,35,44,35]I want to sort the list in descending order, so I use this:
sortedlst = sorted(slst, reverse = True)I also want the original index in a sorted position as well. Like this:
sortedlstindx = [1,0,4,2,3,5]for that I use this code:
sortedindx = [elem.index(lst) for elem in sorted(lst, reverse = True)]The result I got is this:
sortedindx = [1,0,4,2,2,2]How can I modify the code to give the result I want?
It's a shame I cannot use dict or set to help with this problem. No libraries import either sadly.
perfringo write Sep-21-2022, 10:08 AM:
Nobody expects the Spanish Inquisition! Our chief weapon is surprise! Surprise and fear. Fear and surprise. Let me tell you something: when you're looking at your thread tonight and manic silence meets you don't come cryin' to me. Instead do use respective tags while posting code, output and errors (refer to BBCode help). This empowers others to help you. And... Always Look on the Bright Side of Life: I added them this time but if in the future you do it all by yourself I feel happy.
Nobody expects the Spanish Inquisition! Our chief weapon is surprise! Surprise and fear. Fear and surprise. Let me tell you something: when you're looking at your thread tonight and manic silence meets you don't come cryin' to me. Instead do use respective tags while posting code, output and errors (refer to BBCode help). This empowers others to help you. And... Always Look on the Bright Side of Life: I added them this time but if in the future you do it all by yourself I feel happy.