cluelessguy102
cluelessguy102

Reputation: 47

How many words in a list

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

Answers (1)

Ajax1234
Ajax1234

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

Related Questions