Does All () return a generator?

So, I want to check if the list is sorted. After reading this page, I did the following:

ll = [ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 ]
all(b >= a for a, b in zip(ll, ll[1:]) )

Output

<generator object <genexpr> at 0x10d9ecaa0>

So, all()return the generator. But this is what the Python documentation says about all():

Return True if all elements of the iterable are true (or if iterable is empty)

What am I missing?

+3
source share
1 answer

This is the problem of these stupid star imports:

from numpy import *

ll = [ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 ]
all(b >= a for a, b in zip(ll, ll[1:]) )
#>>> <generator object <genexpr> at 0x7f976073fdc0>

Python allworks great.

You can access it through the module __builtin__in the python2 module and builtinsin python3:

import __builtin__
__builtin__.all(b >= a for a, b in zip(ll, ll[1:]))
+11
source

All Articles