Python - Check if part of element is in set
<p>I have a set with this output:</p>

<pre><code> set( [Rule(chain='OUTPUT', num='3', pkts='0', bytes='0', target='ACCEPT', prot='tcp', opt='--', inp='*', out='*', source='0.0.0.0/0', destination='10.10.7.84', extra='tcp spt:7390'), 
 Rule(chain='INPUT', num='1', pkts='0', bytes='0', target='ACCEPT', prot='tcp', opt='--', inp='*', out='*', source='148.100.0.0/16', destination='0.0.0.0/0', extra='tcp dpt:7390'), 
 Rule(chain='INPUT', num='3', pkts='0', bytes='0', target='ACCEPT', prot='tcp', opt='--', inp='*', out='*', source='10.10.7.84', destination='0.0.0.0/0', extra='tcp dpt:7390')])
</code></pre>

<p>I want to check if an element matches an item in this set, but disregarding</p>

<pre><code>num='', pkts='', bytes=''
</code></pre>

<p>Is this possible?</p>

<p>Untested code, but this is one way of going about it. If this rule should extend to any kind of equality check, I advise modifying the magic <code>__eq__(self, other)</code> method of the <code>Rule</code> class with the <code>rules_match</code> logic.</p>

<pre><code>def rules_match(rule1, rule2):
    attributes_to_check = ['chain', 'target', 'prot', 'opt', ...]
    return all(getattr(rule1, attribute) == getattr(rule2, attribute) for attribute in attributes_to_check)

def rule_in_set(rule, rule_set):
    return any(rules_match(rule, i) for i in rule_set)
</code></pre>

python