Is there a fast way to sort this list :
list = ['J', 'E', 3, 7, 0]
in order to get this one (numeric first, and then alpha) in python? :
list = [0, 3, 7, 'E', 'J']
Since you're dealing with numbers (that, in this case, are <10) and strings, you can simplify your key and remove the lambda:
>>> sorted(lst, key=str)
[0, 3, 7, 'E', 'J']
Or, even better, use list.sort for an in-place sorting.
>>> lst.sort(key=str)
>>> lst
[0, 3, 7, 'E', 'J']
Each item will be sorted based on the ASCII value of the str-ified value.
Note that, if you're dealing with numbers >=10 (highly likely), then this solution will end up sorting the numbers lexicographically. To get around that, you will end up needing the lambda.
>>> lst.sort(key=lambda x: (isinstance(x, str), x)))
Which is @jpp's solution.
Lorlist_as variable names.