Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #[19] [Python] #6072

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/python/Garkatron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import re

# ! Coded by Garkatron
# ! https://github.com/Garkatron

# ? -------------------------------------------------------------------------------------- ? #

# * Crea un programa que analice texto y obtenga:
# ! Número total de palabras. V
# ! Longitud media de las palabras. V
# ! Número de oraciones del texto (cada vez que aparecen un punto). V
# ! Encuentre la palabra más larga. V
# Todo esto utilizando un único bucle.

# ? -------------------------------------------------------------------------------------- ? #

# ! Functions

def get_words(text:str)->[]:
words=re.split(r'[\s,;.:]+',text)
return words

def max_length_word(words:list)->int:
return max(words, key=lambda v: len(v))

def get_sentences(text:str)->int:
return text.split(".")

def word_mean(words:list)->int:
return sum(map(lambda w: len(w),words))/len(words)


# ! To execute

if __name__=="__main__":

# ! Getting the values
text=input("Insert text: ")
words=get_words(text)
words_count=len(words)
mean_word_lenght=word_mean(words)
sentences=get_sentences(text)
sentences_number=len(sentences)
max_length_word=max_length_word(words)

# ! Printing values
print("----------------------------------------")
print("Analisyng text: ", text)
print("----------------------------------------", "\n")

print("Words: ", words)
print("Words count: ", words_count)
print("Max length word: ", max_length_word)
print("Mean word length: " ,mean_word_lenght, "\n")

print("Sentences: ", sentences)
print("Sentences count: ", sentences_number, "\n")