If given the string "John Doe;Lodging;123;050617", which is a line within a file, I need to remove everything before and including the first semicolon, and after and including the last one. How can I do that without removing my ability to later split the remaining substring?
Previous questions do not address removing the portions once separated while retaining the portion needed for further use.
Stepwise for clarity:
string = "John Doe;Lodging;123;050617" lst = string.split(';') lst = lst[1:-1] string = ';'.join(lst) print(string) >>> 'Lodging;123'
As one line:
';'.join('John Doe;Lodging;123;050617'.split(';')[1:-1]) >>> 'Lodging;123'