Sort a list with certain values staying in constant positions

Viewed 2801

I have a list of strings. I want to only sort values that meet a certain condition. Consider this list

['foo','bar','testa','python','java','abc']

and I only want to sort the values with an a in them. The result should look like this

['foo','abc','bar','python','java','testa']

The elements with a will change places appropriately, but the other elements retain their original positions.

I have absolutely no idea how to implement this, so I hope someone else does. Can someone show me how to do this?

5 Answers
Related