I am trying to make a program that counts the occurrences of a letter in a string, but I don't know how to make it case insensitive while preserving the original letter.
I tried assigning each item to a dictionary with the key being the number of occurrences in the string but, if I say for example, abA
it will count A
and a
as different letters.
import operator
def first_non_repeating_letter(string):
string = string.lower()
di = {}
for i in string:
di[i] = string.count(i)
if all(value > 1 for value in di.values()):
return ""
else:
var = min(di.items(), key=operator.itemgetter(1))[0]
return var
Output: Instead of
output = {"a":1 , b:"1" , "A":1}
I want:
output = {"A/a" : 2, "b":1}
and returning: the repeated letter is A or a