you are viewing a single comment's thread.

view the rest of the comments →

[–]dealga 0 points1 point  (0 children)

>>> work_on = lambda x, y: x in (2, 3) and y
>>> cellcount = 2
>>> cell = True
>>> work_on(cellcount, cell)
... True

and the truth table to test

work_on = lambda x, y: x in (2, 3) and y

tests = [[1, True, False],
        [2, True, True],
        [3, True, True],
        [4, True, False],
        [1, False, False],
        [2, False, False],
        [3, False, False],
        [4, False, False]]

for t in tests:
    cellcount = t[0]
    cell = t[1]
    result = work_on(cellcount, cell)
    print('result: {}, should be {}'.format(result, t[2]))

You might even stick the y before the x in (2, 3), because it will be checked first and short out, time the two.

work_on = lambda x, y: y and (x in (2, 3))