I want to get an input from the console that is a text with several lines. Since I want to do it all in a single input I have to mark '\n' in the middle to signal the different lines. After I get the input I want to save the text in a matrix where each line is a line from the text with the words separated.
This is my function to do so:
def saveText(text):
text = text[6:len(text)-6]
line = 0
array = [[]]
cur = ""
for i in range (len(text)):
if (text[i] == '\n'):
line+=1
array.append([])
else:
if ((text[i] == ' ' or text[i] == ',' or text[i] == ';' or text[i] == '.') and cur != ""):
array[line].append(cur)
cur = ""
else:
cur += text[i]
return array
However, when I print the variable array it appears as a matrix with only one line, and besides the '\n' are counted as words, they also appear as '\n'.
Can anyone help me with this?