“Python Count Postacie” Kod odpowiedzi

Policz znaki w Pythonie String

>>> sentence = 'Mary had a little lamb'
>>> sentence.count('a')
4
Cheerful Cormorant

Python Count Postacie

# Basic syntax:
import re
len(re.findall('[characters]', your_string))

# Example usage:
# say you want to count all G, g, C, or c characters in the following DNA seq
len(re.findall('[GgCc]', "ACGTGCAcgattcgatCGCTAGCTAG"))
--> 14
Charles-Alexandre Roy

Program Python, który liczy wszystkie postacie w zdaniu

#Python program count all characters in a text

root = "..\\Desktop\\text.txt"
file = open(root, 'rt', encoding="utf-8")
data = file.read()

counter = data.count('a')+data.count('A')+data.count('b')+data.count('B')+data.count('c')+data.count('C')+data.count('d')+data.count('D')+data.count('e')+data.count('E')+data.count('f')+data.count('F')+data.count('g')+data.count('G')+data.count('h')+data.count('H')+data.count('i')+data.count('I')+data.count('g')+data.count('G')+data.count('k')+data.count('K')+data.count('l')+data.count('L')+data.count('m')+data.count('M')+data.count('n')+data.count('N')+data.count('o')+data.count('O')+data.count('p')+data.count('P')+data.count('q')+data.count('q')+data.count('r')+data.count('R')+data.count('s')+data.count('S')+data.count('t')+data.count('T')+data.count('u')+data.count('U')+data.count('v')+data.count('V')+data.count('w')+data.count('W')+data.count('x')+data.count('X')+data.count('y')+data.count('Y')+data.count('z')+data.count('Z')

print(counter)
#684004
futurespoir

Odpowiedzi podobne do “Python Count Postacie”

Pytania podobne do “Python Count Postacie”

Więcej pokrewnych odpowiedzi na “Python Count Postacie” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu