I'm trying to find the co shortest words and co longest words in a given dictionary with the keys being the words. When I sort the dictionary, my code below doesn't do that. I get "And" for shorts and "yours" for longs. What is the problem?
def build_report(freq):
report={}
#for shorts:
sorted(freq.keys())
print(sorted(freq.keys()))
shortest=sorted(freq.keys())[0]
shorts=list()
shorts.append(shortest)
print(shorts)
report["shorts:"]=shorts
#for longs:
longest=sorted(freq.keys(),reverse=True)[0]
print(sorted(freq.keys(),reverse=True))
longs=list()
longs.append(longest)
print(longs)
report["longs:"]=longs
This is the freq I'm inputting:
freq={'I': 1, 'heaven': 1, 'filled': 1, 'their': 1, 'termed': 1, 'of': 4, 'And': 3, 'parts': 1, 'neer': 1, 'to': 2, 'song': 1, 'poets': 1, 'The': 1, 'a': 2, 'were': 2, 'verse': 1, 'your': 6, 'knows': 1, 'not': 1, 'half': 1, 'number': 1, 'but': 1, 'yours': 1, 'come': 2, 'rage': 1, 'age': 2, 'Though': 1, 'men': 1, 'fresh': 1, 'heavenly': 1, 'say': 1, 'alive': 1, 'truth': 1, 'this': 1, 'If': 2, 'than': 1, 'old': 1, 'believe': 1, 'Which': 1, 'that': 1, 'You': 1, 'faces': 1, 'yet': 1, 'poet': 1, 'in': 4, 'life': 1, 'most': 1, 'earthly': 1, 'will': 1, 'hides': 1, 'my': 3, 'papers': 1, 'is': 1, 'stretched': 1, 'rights': 1, 'eyes': 1, 'it': 3, 'yellowed': 1, 'Such': 1, 'So': 1, 'all': 1, 'lies': 1, 'the': 1, 'an': 1, 'as': 1, 'write': 1, 'child': 1, 'deserts': 1, 'shows': 1, 'tongue': 1, 'twice': 1, 'Be': 1, 'high': 1, 'some': 1, 'could': 1, 'should': 2, 'and': 2, 'touched': 1, 'like': 1, 'would': 1, 'Who': 1, 'tomb': 1, 'numbers': 1, 'antique': 1, 'scorned': 1, 'metre': 1, 'time': 2, 'touches': 1, 'be': 1, 'with': 2, 'true': 1, 'beauty': 1, 'rhyme': 1, 'less': 1, 'But': 1, 'graces': 1, 'live': 1}