:
def forever():
while True:
yield 1
. , , , (-, , , ) , , :
len(list(the_iterable))
, : ? , .
, , :
num_elements = len(the_iterable)
for element in the_iterable:
...
:
num_elements = 0
for element in the_iterable:
num_elements += 1
...
, , :
num_relevant = len(x for x in xrange(100000) if x%14==0)
( ):
num_relevant = len([x for x in xrange(100000) if x%14==0])
sum, , , , , :
num_relevant = sum(1 for _ in (x for x in xrange(100000) if x%14==0))
, , , :
def exhaustive_len(iterable):
length = 0
for _ in iterable: length += 1
return length
exhaustive_len(x for x in xrange(100000) if x%14==0)
, , , , :
def yield_numbers():
yield 1; yield 2; yield 3; yield 5; yield 7
the_nums = yield_numbers()
total_nums = exhaustive_len(the_nums)
for num in the_nums:
print num
exhaustive_len .
EDIT: Ah exhaustive_len(open("file.txt")), , , , list.