import re astring = 'hello world' revwords = ' '.join(reversed(astring.split())) print(revwords)