I’ve been trying to find the largest result in a list – using the confidence value.
Examples of the lists:
[[{u'categories': [u'health-beauty'], u'confidence': 0.3333333333333333},
{u'categories': [u'activities-events'], u'confidence': 0.6666666666666666}]]
Would return the activities-events dictionary
[[{u'categories': [u'home-garden'], u'confidence': 0.3333333333333333},
{u'categories': [u'None of These'], u'confidence': 0.3333333333333333},
{u'categories': [u'toys-kids-baby'], u'confidence': 0.3333333333333333}]]
Would return all three as they are equal
[[{u'categories': [u'entertainment'], u'confidence': 1.0}]]
Would return entertainment
I tried to utilise python’s max function:
seq = [x['confidence'] for x in d[0]]
max(seq)
but that just returns the value
You can find the maximum confidence as in your own example, then use
filterto create a list of all the maximum records:As noted in the comment below,
filtercould be replaced with list comprehension: