words = {'apple', 'plum', 'pear', 'peach', 'orange', 'cherry', 'quince'}
d = {}
for x in sorted(words):
if x not in d:
d[len(x)]=x
d[len(x)].append(x)
print(d)
AttributeError: 'str' object has no attribute 'append'
The goal of the program is to have a multiple keys, distinguished by word length (i.e., 4, 5, or 6 letters), that store alphabetized values:
{4: 'pear', 'plum' 5: 'apple', 'peach' 6: 'cherry', 'orange', 'quince'}
I am having issues adding items to a key. What I am currently getting as my output is (without the append line):
{4: 'plum', 5: 'peach', 6: 'quince'}
so it seems to be erasing the previous loops entry. The update and append commands are coming back with errors.