Open geotom opened 6 years ago
If we need to iterate only once, it is better to use a generator expression instead of a normal list comprehension!
(x*2 for x in range(256))
[x*2 for x in range(256)]
By using list(generator_expr) we would get the same result when needed.
Check the code where we use comprehensions and replace these when possible (https://medium.freecodecamp.org/python-list-comprehensions-vs-generator-expressions-cef70ccb49db). Also look at Async comprehensions introduced with python 3.6 https://www.blog.pythonlibrary.org/2017/02/14/whats-new-in-python-asynchronous-comprehensions-generators/
If we need to iterate only once, it is better to use a generator expression instead of a normal list comprehension!
Generator expression
(x*2 for x in range(256))
List comprehension
[x*2 for x in range(256)]
By using list(generator_expr) we would get the same result when needed.
Check the code where we use comprehensions and replace these when possible (https://medium.freecodecamp.org/python-list-comprehensions-vs-generator-expressions-cef70ccb49db). Also look at Async comprehensions introduced with python 3.6 https://www.blog.pythonlibrary.org/2017/02/14/whats-new-in-python-asynchronous-comprehensions-generators/