Last active
May 1, 2020 20:21
-
-
Save r-trigo/8c3fd69d1a1dc83e1688d0e888273abe to your computer and use it in GitHub Desktop.
Python split() recreation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# obter um array com as palavras da frase | |
print("Escreva a frase a fragmentar:") | |
frase = input() | |
palavras = [] | |
# se nao tiver ponto final passa a ter | |
if len(frase) != ".": | |
frase = frase + "." | |
for letra in frase: | |
i = frase.index(letra) | |
if letra == ".": | |
# fim de frase | |
palavras.append(frase[:-1]) | |
print(palavras) | |
elif letra == " ": | |
# guardar palavra | |
palavras.append(frase[0:i]) | |
# retirar palavra à frase | |
frase = frase[i+1:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment