3 ms·
It depends on the situation, I guess. You can “cache” specific results inside generator object/function and still return generator. If your result is something
by deno 17y ago
It depends on the situation, I guess. You can “cache” specific results inside generator object/function and still return generator. If your result is something one can iterate over you should return generator. If you then need list you can just convert your generator into one. If your list is actually some kind of data structure than perhaps a more object-oriented approach is suitable? Python is not functional language after all. But if all you need is to iterate more than once over generator you can just cache it as a list and reuse if needed.