# why can’t i take b = string.count(0,s , len(string)) OR b = string.count(s, len(string)) and how to sort dictionary according to no of letters??string = "MISSISSIPPI"
dictionary={}
for s in set(string):
b = string.count(s,0 , len(string))
dictionary[s] = b
print(dictionary)
I think you have not understood the question. You output should be something like this:
{“M”:1, “I”: 4, “S”:4 ,”P”:2}
string = "MISSISSIPPI"
d = {}
m_count = 0
i_count = 0
s_count = 0
p_count = 0
for i in string:
if i == "M":
m_count = m_count+1
elif i == "I":
i_count = i_count+1
elif i == "S":
s_count = s_count+1
elif i == "P":
p_count = p_count+1
d['M'] = m_count
d['I'] = i_count
d['S'] = s_count
d['P'] = p_count
print d