I'm trying to solve a problem that involves the figuring out if one list is a subset of another, except there is an added twist that the code should consider the list a subset even if the values don't completely match, as long as it's within a tolerance.
EXAMPLE:
If I have the lists:
A = [0.202, 0.101]
B = [0.1, 0.2, 0.3, 0.4, 0.5]
and I set a tolerance of tol = 0.002
, then the code should return that list A
is a subset of list B
since its values are within the tolerance (0.202 <= 0.2 + tol
, 0.101 <= 0.1 + tol
).
I don't have much code to show since I know how to figure out if a list is a subset of another using the traditional issubset
function, but I'm not sure how to incorporate the tolerance into it.