, :
-, . , , :
def check(word):
return len(word) >= 2 and word[0] == word[-1]
sum(1 for word in words if check(word))
, ( ) , :
len(filter(check, words))
There itertools.ifilter, but if you use this, you need to use the expression again sum, so it will not become more clear.
The trick sumarises so often that I am surprised that there is no standard library call to count the number of elements in the iterator (if there is, I did not find it). Alternatively, it makes sense if lenit consumes and counts the number of records in the iterator, if it does not __len__, but it is not.
source
share