For two lists, l1 and l2, how to check that for all e1 ∈ l1, ∃p(e1,e2) where e2 is some element in l2, efficiently in python?

ساخت وبلاگ

Vote count: 0

Ok, not sure if that was the best title, but I have two python lists. L1 and L2 which both have elements of type T and do not have the same length.

I have a function p(T,T) which is a predicate checking a property about two elements of type T.

I would like to check that for all elements e in L1, p(e,e') holds, where e' is SOME element in L2. so basically for each element in L1 I go over the second list, and check if the predicate holds for any of the elements. But I also want to check the same thing for the other list.

p(T,T) is symmetric. So if p(e,e') then p(e',e). I do not want to do the same thing twice because of that symmetry. I need to somehow record that if I see p(e,e') then I know p(e',e) and not have to check again for the second list.

What is the best way to do this in python? I thought about having another field for each element e1 in each list, telling us whether p(e1, e2) holds, where e2 is a member of the other list. But I think that requires copying both of those lists so I don't mutate them. Is there any good way to do this?

asked 30 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 251 تاريخ : جمعه 15 مرداد 1395 ساعت: 22:50