python programs to count letters in each word of a sentence -


i'm pretty new python , need program not counts words input sentence counts number of letters in each word. have far. appreciated!

def main():     s = input("please enter sentence: ")     words = s.split()     wordcount = len(words)     print ("your word , letter counts are:", wordcount) main() 

you can generate mapping words word lengths, follows:

s = "this sentence" words = s.split() letter_count_per_word = {w:len(w) w in words} 

this yields

letter_count_per_word == {'this': 4, 'a': 1, 'is': 2, 'sentence': 8} 

Comments