0

string='hhelloo'

output must be 'e' because it is least occurred character in string.

lst=[1,1,2,3,4,5,5]
moc=min([(lst.count(chr),chr) for chr in (lst)])
print(moc)
cs95
  • 379,657
  • 97
  • 704
  • 746

1 Answers1

0

You could use the last element from Counter.most_common()

from collections import Counter

print(Counter('hhelloo').most_common()[-1][0])

This wouldn't be very efficient however. For a more efficient method, take a look at this answer: https://stackoverflow.com/a/4743286/5946921

It implements a least_common function in a similar way to how Counter.most_common is implemented

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52