# Revision history [back]

A few comments: (1) don't do list(powerset(M)). Instead, just do for Q in powerset(M): if you're going to iterate over something, there is no need to turn it into a list first, and that may take time and may also require a lot of memory. for Q in powerset(M) should be faster and more memory efficient. Similarly, you may be able to have Lab_Funs return an iterator, not a list: since you are going to iterate over the entries, there is no need to compute the whole list all at once. Also, please look at itertools to see what it provides.

A few comments: (1) don't do list(powerset(M)). Instead, just do for Q in powerset(M): if you're going to iterate over something, there is no need to turn it into a list first, and that may take time and may also require a lot of memory. for Q in powerset(M) should be faster and more memory efficient. (2) Similarly, you may be able to have Lab_Funs return an iterator, not a list: since you are going to iterate over the entries, there is no need to compute the whole list all at once. (3) Also, please look at itertools to see what it provides.

A few comments: (1) don't do list(powerset(M)). Instead, just do for Q in powerset(M): if you're going to iterate over something, there is no need to turn it into a list first, and that may take time and may also require a lot of memory. for Q in powerset(M) should be faster and more memory efficient. (2) Similarly, you may be able to have Lab_Funs return an iterator, not a list: since you are going to iterate over the entries, there is no need to compute the whole list all at once. (3) Also, please look at itertools to see what it provides.

Edit:

Minor simplification: change

IT=iter(powerset(M))
LIS=[];
for g in IT:


to

LIS=[];
for g in powerset(M):


More significant change: replace Lab_Funs by an iterator: don't compute the whole thing at once:

class Lab_Funs_iter:
def __init__(self, M):
self.M = M

def __iter__(self):
self.powerset = powerset(M)
return self

def __next__(self):
g = self.powerset.__next__()
M = self.M
F = []
for s in range(len(M)):
if M[s] in g:
F=F+[(M[s],1)];
else:
F=F+[(M[s],0)]
return F


Then do for f in Lab_Funs_iter(M): Do an internet search for "python iterator" to find more about Python iterators. I don't know what problems you're having and I can't test your code because I don't know what plus is supposed to do.