I want to sort a list in a way that the elements (sublists) which have a certain string (of my choosing) come first. I'd like to do this with the key parameter in Python's sort()
method.
For example, if I have
Input
l1 = [["hello", 1, 65, 331],["goodbye", 653, 43, 9], ["example", 22, 123, 92]]
I'd like to use l1.sort()
to sort the list in a way that, given "example" as the parameter, sorts the list like this:
Output
[["example", 22, 123, 92], ["hello", 1, 65, 331], ["goodbye", 653, 43, 9]]
.
Is this possible?