-1

I have been struggling with this problem so I would appreciate your help!

My university task is to write this method:

def removeRedundant(clauses, setOfSupport):

    newClauses = set()
    for clause in clauses:
        if not clause.isRedundant(clauses):
            newClauses.add(clause)

    newSOS = set()
    for clause in setOfSupport:
        if not clause.isRedundant(setOfSupport):
            newSOS.add(clause)

    return newClauses, newSOS

in a different way which avoids these 2 for loops. I am wondering if it is possible to merge these two loops in one or there is even some other way to replace them?

Thank you in advance!

pobro123
  • 183
  • 1
  • 1
  • 9

1 Answers1

0

No, you won't be able to get rid of all the loops, but it's possible to merge the two loops into one:

from itertools import izip_longest

def removeRedundant(clauses, setOfSupport):
    newClauses, newSOS = set(), set()

    for clause, support in izip_longest(clauses, setOfSupport, fillvalue=None):
        if (clause is not None) and (not clause.isRedundant(clauses)):
            newClauses.add(clause)
        if (support is not None) and (not support.isRedundant(setOfSupport)):
            newSOS.add(support)

    return newClauses, newSOS
ForceBru
  • 43,482
  • 10
  • 63
  • 98