How do I construct a sort with conditions in python? Let's say if I have a list
a: [-1, 3, 4, 2, -1, -1, 1, 0] How do I sort only the elements that is not -1? (In return:
[-1, 0, 1, 2, -1, -1, 3, 4] ) How do I sort every other element? (In return a: [-1, 3, -1, 2, 1, -1, 4, 0] ) The syntax of the code is wrong, but would it be something similar to this?
result=sorted(a, key=lambda x: x!=-1,reverse=True) result=sorted(a, key=lambda x: [::2],reverse=True)