Easiest way to calculate number of character in string
no_spam at tauth.de
Wed Dec 21 15:03:52 CET 2005
I have a string in which I want to calculate how often the character ';'
occurs. If the character does not occur 42 times, the ";" should be added so
the 42 are reached.
My solution is slow and wrong:
for Position in range (0, len(Zeile)):
if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
if AnzahlSemikolon < 42:
for Zaehler in range(AnzahlSemikolon, 42):
Zeile = Zeile + ';'
Dreckskram = Dreckskram +1
How can this be achieved easily?
More information about the Python-list