how search in texts with python? [duplicate]

Solution 1:

The str.split() method without an argument splits on whitespace:

>>> "many   fancy word \nhello    \thi".split()
['many', 'fancy', 'word', 'hello', 'hi']

Solution 2:

import re
s = "many   fancy word \nhello    \thi"
re.split('\s+', s)