count the number of characters in a string
idea: Use Set () set to repeat, and then count () the number of words in the original list () out of the set
s = "I am very very very love Python"
word = S.split ("")
#print word
#print set (S.split (""))
Set (S.split (")):
x = S.count (word)
print(number of {}}. Format (word,x))
The results show:
The number of I is 1
The number of very is 3
The number of AM is 1
The number of love is 1
The number of Python is 1
idea: Create a new dictionary, Word as key, number as value, find a key,value+1
>>> Help (D.get ())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Typeerror:get expected at least 1 arguments, got 0
>>> Help (D.get)
Help on built-in function get:
Get (...) method of Builtins.dict instance
D.get (K[,d])-> D[k] if k in D, else D. D defaults to None.
s = "I am very very very love python"
counter = {}
s.split ():
# If Word isn't in COUNTER.K Eys ():
# Counter[word] = 0
Counter[word] = counter.get (Word, 0) + 1
print(counter)
The results are:
{' I ': 1, ' very ': 3, ' AM ': 1, ' Love ': 1, ' Python ': 1}