fd = open('words_alpha.txt', 'r')
lines = fd.readlines()
fd.close()
print('number of all words in the dictionary =', len(lines)))
print('number of five-letter words in the dictionary = ', len(lines))))
for line in lines:
line = line.strip()
if len(line) == 5:
print(line ,len(line))
How do we get the five-letter word count here?
python
words5 = [ line.strip() for line in lines if len(line.strip()) == 5 ]
If you do this, words5 will only collect words of length 5. If you don't know this grammar, you should search for list compliance and list abbreviation.
string[start:end:step]
https://www.freecodecamp.org/news/how-to-substring-a-string-in-python/
Search keyword: how to substring in python
606 Uncaught (inpromise) Error on Electron: An object could not be cloned
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
567 Who developed the "avformat-59.dll" that comes with FFmpeg?
884 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.