Opinions seem to be mixed on this -- is there a Pythonic "right way" to do this?
I think empty iterator is better because iterating over nothing is faster then first checking if returned value is not None and then iterate over or not.
for x in function():
do_something()
value = function()
if value is not None:
for x in value:
do_something()
Just look at this.
Also normally you dont initialize iter attributes with None, but with empty iter object.
self.list_of_users = []
not
self.list_of_users = None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With