Split the strings using str.split and str.rsplit and then match the first and last word:
>>> a = "Hello Mars"
>>> b = "Venus Hello"
#This compares first word from `a` and last word from `b`.
>>> a.split(None, 1)[0] == b.rsplit(None, 1)[-1]
True
If you only want to compare first and second word then use just str.split.
>>> a.split()
['Hello', 'Mars']
>>> b.split()
['Venus', 'Hello']
#This compares first word from `a` and second word from `b`.
>>> a.split()[0] == b.split()[1]
True
What does str.split and str.rsplit return:
>>> a = "Hello Jupiter Mars"
>>> b = "Venus Earth Hello"
>>> a.split(None, 1) #split the string only at the first whitespace
['Hello', 'Jupiter Mars']
>>> b.rsplit(None, 1) #split the string only at the last whitespace
['Venus Earth', 'Hello']