Check if dict key is a substring of any other element in the dictionary in Python?
<p>I've got a dictionary <strong>ngram_list</strong> as follows:</p>

<pre><code>ngram_list = dict_items([
    ('back to back breeding', {'wordcount': 4, 'count': 3}),
    ('back breeding', {'wordcount': 2, 'count': 5}),
    ('several consecutive heats', {'wordcount': 3, 'count': 2}),
    ('how often should', {'wordcount': 3, 'count': 2}),
    ('often when breeding', {'wordcount': 3, 'count': 1})
])
</code></pre>

<p>I want to sort the list from the shortest wordcount to the largest and then loop through the dictionary and if the key is a substring of any other item, delete it (the substring item.)</p>

<p>Expected output:</p>

<pre><code>ngram_list = dict_items([
    ('several consecutive heats', {'wordcount': 3, 'count': 2}),
    ('how often should', {'wordcount': 3, 'count': 2}),
    ('often when breeding', {'wordcount': 3, 'count': 1}),
    ('back to back breeding', {'wordcount': 4, 'count': 3})
])
</code></pre>