I would like to sort list A based on list B(descending order) such that if two list A,B are
A=["k","a","l","d"]
B=[4,3,7,22]
after sorting, ( sort A based on desc(B) )
A=["d","l","k","a"]
However if B=[0,0,0,0]
I would like A to remain A=["k","a","l","d"] after sorting too
so wherever values are equal, the original order must be retained.
if B=[0,22,5,0] and A=["k","a","l","d"]
then, after sorting, A=["a","l","k","d"]
I have tried using A= [x for _,x in sorted(zip(B,A),reverse=True)],
- with if
A=["k","a","l","d"]andB=[0,0,0,0], this givesA=["a","d","k","l"]but I want A to remainA=["k","a","l","d"] - with if
A=["k","a","l","d"]andB=[0,22,5,0], this givesA=["a","l","d","k"]but I want A to beA=["a","l","k","d"]
How do I achieve this?