i’m avoiding real work, so here is a simple program which will work IF each word is on a separate line in the file.
If this is not your structure you’ll need to do a bit more work, but python is incredibly friendly for handling files so it should be simple.
maxlength=0
f=open(‘wordlist.txt’) ## opens wordlist.csv to read and assigns to f
wordlist = f.readlines() ## reads entire file into word list
## (warning may be a problem with BIG files)
## note multiple words on a single line treated as one long word
no_of_words=len(wordlist)
print “Total words read = “,no_of_words
for each in wordlist:
^ a=len(each) -1
^ if a>maxlength: maxlength=a
resultlist=[0]
for val in range(0,maxlength): resultlist.append(0) ## build list of size required
print “Longest word is = “,maxlength
for each in wordlist:
^ a=len(each)-1 ## subtract 1 as word length is over counted
^ resultlist[a] = resultlist[a] +1
print “== Results: ==”
for result in range(1,maxlength+1):
^ print “Words with”,result,”characters:”,resultlist[result]
sorry – can’t get code formatting to work – lines starting ^ should be indented (delete the ^)