Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
num_letters = sum(1 for c in no_code_text if c.isalpha())
num_numbers = sum(1 for c in no_code_text if c.isdigit())
num_alphanum = sum(1 for c in no_code_text if c.isalnum())
num_otherchars = num_chars - num_alphanum
results.append(TextFeature('Number of characters', num_chars, group_by))
results.append(TextFeature('Number of letters', num_letters, group_by))
results.append(TextFeature('Number of numbers', num_numbers, group_by))
results.append(TextFeature('Number of other characters', num_otherchars, group_by))
character_counts = Counter(no_code_text.lower())
for c in sorted(character_counts.items()):
try:
results.append(TextFeature('Character count for "{}"'.format(c[0].encode('unicode_escape')), c[1], group_by))
except AttributeError:
results.append(TextFeature('Character count for "{}"'.format(c[0]), c[1], group_by))
results.append(TextFeature('Number of syllables', textstat.syllable_count(no_code_text), group_by))
results.append(TextFeature('Lexicon Count (without punctuation)', textstat.lexicon_count(no_code_text, True), group_by))
results.append(TextFeature('Lexicon Count (with punctuation)', textstat.lexicon_count(no_code_text, False), group_by))
results.append(TextFeature('Number of lower case characters', num_lower, group_by))
results.append(TextFeature('Number of upper case characters', num_upper, group_by))
return results
def split_by_syllables(syls, words):
s_count = 0
split = 0
while s_count < syls and split < len(words):
s_count += round(textstat.syllable_count(words[split]))
split += 1
if s_count != syls:
raise ValueError("Words do not evenly split")
return words[:split], words[split:]