So I've been following along some of the projects from the 'Big Book of Small Python Projects' by Al Sweigart and ive been attempting to follow along one of the projects, however Ive been stuck on this segment of code for a while now and was wondering if anyone could help. Anytime i run the code I keep getting an error on this line "WORDS[i] = WORDS[i].strip().upper()". It says "'str' object does not support item assignment" and I am unsure how to fix. Any help is greatly appreciated.
# Load the WORDS list from the text file
with open('sevenletterwords.txt') as wordListFile:
WORDS = wordListFile.readline()
for i in range(len(WORDS)):
# Convert each word to uppercase and remove the trailing newline
WORDS[i] = WORDS[i].strip().upper()
WORDSmeant to be a single line?WORDSis a string and cannot be assigned through indexing. Perhaps just useWORDS.upper().strip(), rather than the loop.