Howdy, codeboys and codegirls!
I ran into a simple problem, a seemingly simple solution. But, being a neophyte of Python, I feel that somewhere there is a better approach.
Say you have a list of mixed strings. There are two main types of strings in a bag: in them - = (a = potato) and without them (Lady Jane). You need to sort them by two lists.
The obvious approach is as follows:
for arg in arguments:
if '=' in arg:
equal.append(arg)
else:
plain.append(arg)
Is there any other, more elegant way in it? Sort of:
equal = [arg for arg in arguments if '=' in arg]
but to sort by multiple lists?
But what if you have several data types?
Rince source
share