O
O
Oleg Wock2015-08-25 21:07:45
Python
Oleg Wock, 2015-08-25 21:07:45

Is it advantageous to use a generator instead of a set here?

I have a set of all_members, it stores positive integers. So far there are not many of them, but I want to optimize for more loads from the very beginning. So, is it profitable to convert it into a generator if it is then used only in a loop? They say that generators, if needed only for a cycle, are more productive, but in order for him to generate elements of a set, he needs to store this set somewhere? Tell

all_members = itertools.chain.from_iterable([all_members])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-08-25
@lega

Generators are beneficial if (all) data does not need to be stored, i.e. they took it somewhere, transferred it somewhere, as a result, it turns out, as it were, a flow of information without consuming memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question