0

in the expression, any(not (i % 6) for i in range(1, 10))

does the any() argument not (i % 6) for i in range(1, 10) defines a generator or a list ?

For the moment I understand that in:

g = (not (i % 6) for i in range(1, 10))

g is a generator

and in :

l = [not (i % 6) for i in range(1, 10)]

l is a list

But as we don't invoke any with [] or (), like in any([not (i % 6) for i in range(1, 10)]) or any((not (i % 6) for i in range(1, 10))) I'm confused...

martin-h
  • 69
  • 1
  • 8
  • Thank you for the link ! Unless I get something wrong, my question is more related to what happens internally when you pass the expression to any(), is it evaluated as a list of as a generator ? (And not to answer the question to choose one or another) – martin-h Jan 30 '20 at 09:47
  • 3
    If there are no `[ ]` there is no list – DeepSpace Jan 30 '20 at 09:47
  • 1
    Or https://stackoverflow.com/questions/4799459/why-can-you-omit-the-surrounding-parentheses-for-generators-in-python-when-passi – mkrieger1 Jan 30 '20 at 09:48
  • `any` and `all` accept an iterable. Which can be a list, a generator and any other type that can be iterated over. – Klaus D. Jan 30 '20 at 09:49
  • Thank you ! with https://www.python.org/dev/peps/pep-0289/#id14 and the @DeepSpace answer, I think I got it ! (too bad that the question was closed, I think the answer in https://stackoverflow.com/questions/4799459/why-can-you-omit-the-surrounding-parentheses-for-generators-in-python-when-passi is pretty evasive when 'If there are no [ ] there is no list' provides a very clear answer) – martin-h Jan 30 '20 at 10:02

0 Answers0