PUNCTUATION_MARKS = (',','.','!','?','"\n"','"\t"' )
def count_quantity_words(text):
count_words = 0
for char in text:
if char in PUNCTUATION_MARKS:
count_words += 1
return count_words
PUNCTUATION_MARKS = (',','.','!','?','"\n"','"\t"' )
def count_quantity_words(text):
count_words = 0
for char in text:
if char in PUNCTUATION_MARKS:
count_words += 1
return count_words
>>> def f(x, y):
... print x, y
... return x + y
...
>>> reduce(f, [1, 2, 3, 4, 5])
1 2
3 3
6 4
10 5
15
reduce(lambda x, y: x+y,(1 for x in s if x in (',','.','!','?','"\n"','"\t"')), 0)
reduce(lambda x, y: x + int(y in ',.!?\n\t'), text, 0)