Q:

word fragments checker with a list and for loop analyzer

i'm trying to make a semi-word analyzer, here is my code:
score = 0
letter_combos = ["hel","goo","the"]
sentence = input("Please enter a sentence for anaysing!")
length = len(sentence)
for letter_combos in range (0, length):
    score += 1        
    print(score)

The idea is, if  i entered "hello there i'm good today" it should display the score as 3 but its just printing the length of the sentence. Any help on what I've done wrong and need to fix?

A:

The most Pythonic way of solving your problem is to use list comprehension:
letter_combos = ["hel", "goo", "the"]
sentence = input("Please enter a sentence for analyzing: ")
score = sum(sentence.count(fragment) for fragment in letter_combos)

