def stringi(file):
doc = open(file, 'r')
cont = doc.read()
nums = []
word = ""
for i in cont:
if i != " ":
word += i
else:
nums.append(word)
word = ""
nums.append(word)
doc.close()
return nums
This prints >>> ['This', 'is', 'ship', 'line', '132', '43', 'hello\n']
from a file which has: "This is ship line 132 43 hello"
How do I remove the \n
part or at least a specific character in an element?
(I'm aware that there are modules to do what I want with making each word an element but I'm a beginner and want to learn other ways.)