generic_node_match#

generic_node_match(attr, default, op)[source]#

Returns a comparison function for a generic attribute.

The value(s) of the attr(s) are compared using the specified operators. If all the attributes are equal, then the constructed function returns True.

Parameters:
attrstring | list

The node attribute to compare, or a list of node attributes to compare.

defaultvalue | list

When attr is a string, the default value for that attribute. Otherwise, a list the same length as attr with default values for each attribute.

opcallable | list

When attr is a string, the operator to use when comparing attribute values. Otherwise, a list the same length as attr with operators to for each attribute.

Returns:
matchfunction

The customized, generic node_match function.

Examples

>>> from operator import eq
>>> from math import isclose
>>> from networkx.algorithms.isomorphism import generic_node_match
>>> nm = generic_node_match("weight", 1.0, isclose)
>>> nm = generic_node_match("color", "red", eq)
>>> nm = generic_node_match(["weight", "color"], [1.0, "red"], [isclose, eq])