3

So I want to test if a list is sorted. After reading this page, I did this:

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>

Ok so all() return a generator. But this is what the Python documentation says about all():

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

What am i missing?

Community
  • 1
  • 1
usual me
  • 8,338
  • 10
  • 52
  • 95

1 Answers1

11

This is a problem of those silly 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's all works fine.

You can access it via __builtin__ module in python2 and builtins module in python3:

import __builtin__
__builtin__.all(b >= a for a, b in zip(ll, ll[1:]))
Veedrac
  • 58,273
  • 15
  • 112
  • 169