+ 1
What is char and text ? #phython
I'm bit confused of char and text .Are they function or just variable. if they are function what they do and how to use them for counting text letters. example : I have a file with text "hdnjehc...." i want to count how many times each letter appears.
2 Answers
+ 1
Consider everything that is not numeric to be a string. not char or text, but string.
Every string in python nomatter how many chars it has is a special set, that could be iterates through, or converted into a "normal" python list.
You can iterate through the string with for...in loop. Something like this:
>>> astring = "hdnjehc"
>>> for c in astring:
print (c + ' - ' + str(astring.count(c)))
=====
Result:
h - 2
d - 1
n - 1
j - 1
e - 1
h - 2
c - 1