Python 'in' operator

Hi Chris,

I was developing a new experiment in MWorks and I was looking to use an equivalent of Python’s “in” operator to check if a value is a part of a list. I looked through the MWorks discussion board and saw that you were looking to create a similar operator in the MWorks expression grammar (titled MWorks list variables and logic from Sep ’15). I couldn’t seem to find it in the documentation and I was wondering if you could point me in the right direction.

Best,
Neel

Hi Neel,

Adding such an operator is still on my to-do list, but I haven’t gotten to it yet. In the meantime, you can define an expression macro that uses the py_call function to do the same job:

%define contains (x, y) py_call('(lambda x, y: y in x)', x, y)

Then, in a protocol:

if (contains(my_list, 2)) {
    ...
}

Cheers,
Chris