Reputation: 47
E.g. dic['aet'] = ['ate', 'eat', 'eta'] and dic['pol'] = ['lop', 'pol']
and if I enter a length of word: 3, I want it prints out the longest dictionary values with words of length 3 plus its values from the dictionary.
How would I do this?
count = 0
num = int(input("Enter length:"))
for key, valu in lst.items():
if len(valu) == num:
count = count + 1
for i in valu:
a_list.append(i)
print(a_list, " size:", count)
Output I want from above: ['ate', 'eat', 'eta'] size: 3
Upvotes: 0
Views: 160
Reputation: 71451
You can try this:
num = int(input("Enter length:"))
d = {"aet":['ate', 'eat', 'eta'], 'pol':['lop', 'pol']}
vals = [i for i in d.values() if len(i) >= num]
Upvotes: 1