I want to remove 'canBeGuessed' list items from the 'sortedList' items. The below code does that:
canBeGuessed = ['A', 'B', 'C']
SORTED_FREQUENCIES = 'ZQXJKVBPYGFWMUCLDRHSNIOATE'
sortedList = list(SORTED_FREQUENCIES)
for letter in SORTED_FREQUENCIES:
if letter not in canBeGuessed:
sortedList.remove(letter)
print(f"New sorted List: {sortedList}")
Output: New sorted List: ['B', 'C', 'A']
My question is, why doesn't this work when you change SORTED_FREQUENCIES to sortedList in the for loop? 'letter' in the for loop is the same type/output for both variables:
canBeGuessed = ['A', 'B', 'C']
SORTED_FREQUENCIES = 'ZQXJKVBPYGFWMUCLDRHSNIOATE'
sortedList = list(SORTED_FREQUENCIES)
for letter in sortedList:
if letter not in canBeGuessed:
sortedList.remove(letter)
print(f"New sorted List: {sortedList}")
Output: New sorted List: ['Q', 'J', 'V', 'B', 'Y', 'F', 'M', 'C', 'D', 'H', 'N', 'O', 'A', 'E']
I've checked the output and type of 'letter' and they are the same when looping over SORTED_FREQUENCIES and sortedList.