Let\'s say you have a situation like this:
_, _, _, substring_1, _, substring_2 = some_string.split(\',\')
Is there a shorthand way of expressi
Not a syntactic shortcut, but you might want to use the itemgetter
function from the operator
module:
from operator import itemgetter
my_pair = itemgetter(3, 5)
substring_1, substring_2 = my_pair(some_string.split(','))
Or, define my_pair
to wrap the call to split
as well:
def my_pair(x):
return itemgetter(3,5)(x.split(','))
substring_1, substring_2 = my_pair(some_string)