3 ms·
McCarthy's amb operator in Python
- tmhedberg 15y agoIsn't this essentially what list comprehensions are for? For instance, here's the Pythagorean triple example using a comprehension: [(a, b, c) for a in range(1, 11) for b in range(1, 11) for c in range(1, 11) if a ** 2 + b ** 2 == c ** 2] I understand that the semantics are slightly different, but I'd argue that the benefit of using a built-in, idiomatic Python construct instead of reinventing the wheel is pretty clear. Or am I missing something?
- coconutrandom 15y agoI am definitely not the authority here, so someone correct me. This is giving all combination of values that evaluate to True. [edit] More info here: http://c2.com/cgi/wiki?AmbInPython http://c2.com/cgi/wiki?AmbInPython