views:

91

answers:

1

Hi,

I need to convert a string to another which has removed anything before the second word

Example from this,

string = "xyz anything else"
string2 = "xyz  anything else"
string3 = "xyz   anything else"

to this,

string = "anything else" 
string2 = "anything else"
string3 = "anything else"

The way I've done it doesnt please me at all, it isnt pythonic and it's too large. What it would be the best way to do it in Python?

+6  A: 
s.split(None, 1)[-1]
jcdyer
wow that was shorter than I expected. ^^;;
Pablo
http://docs.python.org/library/string.html#string.split
jcdyer
If you want `"singleword".split(None, 1)` to be safe, better use `-1` index (last item) since the result might not always have length two. If you prefer an error in this case, the present solution is just fine.
kaizer.se
Fixed. Good call.
jcdyer