Extended tuple unpacking with unknown string format

Viewed 82

I have a string that may or may not have a | separator breaking it into two separate parts.

Is there a way to do extended tuple unpacking like this

first_part, *second_part = 'might have | second part'.split(' | ') 

and have second_part == 'second part' rather than ['second part']? If there is no separator, second_part should be ''.

4 Answers
Related