What problem, I can’t get the list to the other function?

Asked

Viewed 136 times

1

def le_textos():
    i = 1
    textos = []
    texto = input("Digite o texto " + str(i) +" (aperte enter para sair):")
    while texto:
        textos.append(texto)
        i += 1
        texto = input("Digite o texto " + str(i) +" (aperte enter para sair):")
    return (textos)
def separa_sentencas():
    '''A funcao recebe um texto e devolve uma lista das sentencas dentro do texto'''
    textos = le_textos()
    sentencas = re.split(r'[.!?]+', textos)
    if sentencas[-1] == '':
        del sentencas[-1]
    return sentencas    



Digite o texto 1 (aperte enter para sair):sadasdasdasdas,asdasdasdasdas.dasd,asdas,dasdasdasdasd,asdasdasdas:dasdas.dasldasdasdasdasd.asdasd,asdasdasdasdasdasdas.das,d,asd.asdasdasdasdasdasd,asd,asd.asdasdasdasdasdasdasdasdasd,asdasdas.dwefqefqegtrwghwrhgwrghwrgh.w
Digite o texto 2 (aperte enter para sair):sadasdasdasdas,asdasdasdasdas.dasd,asdas,dasdasdasdasd,asdasdasdas:dasdas.dasldasdasdasdasd.asdasd,asdasdasdasdasdasdas.das,d,asd.asdasdasdasdasdasd,asd,asd.asdasdasdasdasdasdasdasdasd,asdasdas.dwefqefqegtrwghwrhgwrghwrgh.w
Digite o texto 3 (aperte enter para sair):
Traceback (most recent call last):
  File "G:\estudo de programação\exercicios 09 semana\COH-PIAH.py", line 91, in <module>
    separa_sentencas()
  File "G:\estudo de programação\exercicios 09 semana\COH-PIAH.py", line 30, in separa_sentencas
    sentencas = re.split(r'[.!?]+', textos)
  File "C:\Python33\lib\re.py", line 191, in split
    return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or buffer
>>> 

1 answer

1

What are you passing on to the split not a string, is the very list:

>>> type(textos)
<class 'list'>

Put this list on a loop and capture the words from there:

def separa_sentencas():
    textos = le_textos()
    sentencas = []
    for frase in textos:
        sentencas.append(re.split(r"[.!?]+", frase))
    return sentencas

Browser other questions tagged

You are not signed in. Login or sign up in order to post.