Just change your code to,
import re
def stir_to_list (file):
result = [x.lower() for x in re.findall(r"[\w']+",file)]
return result
Note that I have added lower()
and removed the strip()
function.
I have used a Regular Expression here. All it does is it returns a list with the matching sequence of characters,i.e. without the trailing blank spaces.
After that, all I am doing here is converting each character to lower case. Now if a character is already in lower case then it remains unaffected but an upper case letter will be converted to lower case.
Output:
['i', 'have', 'a', 'big', 'red', 'house']
If you don't know about Regular Expressions, you can look it up here.