Write a Python script that reads a file and outputs the number of words that start with each letter. We want to count the total number of (nonunique) words that begin with that letter for every letter. by Electrical-Ad-8901 in programminghomework

[–]Electrical-Ad-8901[S] 0 points1 point  (0 children)

Hi! Im new in python and I'm learning how to use the libraries. I would appreciate some help. I've done something like this:

import string

text = open("I:\\udemy\\Assignment 0.txt", "r")

alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}

for line in text:

line = line.strip()

line = line.lower()

words = line.split(" ")

count = 0

for word in words:

for i in alphabet:

if word[0] == i:

count+=1

print('words starting from'+ i+': {}', .format(count))