Home > Software design >  Comparing count of items in two lists
Comparing count of items in two lists

Time:09-18

I have two dictionaries as below:

{'a': 2, 'd': 1}

{'a': 2, 'n': 1, 'd': 1, 'ç': 1}

I need to print "true" if the total count of each item in the second dictionary is equal or greater than count of the same item(s) in the first dictionary.

What I mean is:

If total count of "a" in second dictionary >= total count of "a" in first dictionary

AND

if total count of "d" in second dictionary >= total count of "d" in first dictionary

OUTPUT will be TRUE.

I used below statement but somehow it did not work:

kelime_harf_sayisi[i] <= harfler_harf_sayisi[i]

CodePudding user response:

Those are dictionaries (dict), not lists.

d1 = {'a': 2, 'd': 1}
d2 = {'a': 2, 'n': 1, 'd': 1, 'ç': 1}
answer = all(d2[k] >= d1[k] for k in d1)
  • Related