>>> len([1 for i in "qwerty 1.3 esfs".split() if not i.isdigit()])
3
>>> len([1 for i in "qwerty 13 esfs".split() if not i.isdigit()])
2
print(len([1 for i in map(lambda x: x.strip('0123456789,.'), file.read().split()) if i != '']))
>>> len([1 for i in 'год - 2014. день - 244.'.split() if not i.isdigit()]) 6
# coding=utf-8 import re my_string = """\w When the LOCALE and UNICODE flags are not specified, matches any alphanumeric character and the underscore; this is equivalent to the set [a-zA-Z0-9_]. With LOCALE, it will match the set [0-9_] plus whatever characters are defined as alphanumeric for the current locale. If UNICODE is set, this will match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database. """ my_re = re.compile('[\w\[\]\-]+', re.UNICODE) print my_re.findall(my_string) print len(my_re.findall(my_string))
['w', 'When', 'the', 'LOCALE', ..., 'character', 'properties', 'database']
65
text = 'йцукен 12, гшфыва -3.0 Dfg 6.9e+66 6.9e-66, 9999L'.decode('utf-8').replace('-', '') pattern = re.compile(r'(\d+\.?\d*E\+?\d+)|(\d+L)|[\d\W]', re.U|re.I) print(len(pattern.sub(' ', text).split()))
import random a = [random.randint(-6, 6) for i in range(255)] #Определить в последовательности самую длинную субпоследовательность, состоящую из возрастающих значений. rb = le = lb = 0 for i in xrange(1, len(a)): if a[i] <= a[i-1]: if i - rb > le - lb: le, lb = i, rb rb = i print lb, a[lb:le] #Определить в последовательности самую длинную субпоследовательность, все элементы которой больше среднего значения всей последовательности. s = sum(a)/255.0 rb = le = lb = 0 for i in xrange(len(a)): if a[i] <= s: if i - rb > le - lb: le, lb = i, rb+1 rb = i print lb, a[lb:le]