List Contains Item Property

This property describes how LW Python determines whether a list contains a particular value. LW Python first looks in the "Value" stack to find the location of the list in the "Object Store," then searches the list for the value (also specified in the "Value" stack). More formally,

if the following are true:
  • expression state at time t = "call_function_begin"
  • Value Stack at time t = [ [ a, [ Python reference idx, [ ] ] ], stack ]
  • the expression at time t = function call with name: "__contains__" and arguments: args
  • the element at index idx of stack (Python Object Store at time t) = Python list entries

then Return Value at time (t + 1) = stack entries contains a

For example, if the following are true:
  • expression state at time 29 = "call_function_begin"
  • Value Stack at time 29 = [ [ 8, [ Python reference 0, [ ] ] ], [ ] ]
  • the expression at time 29 = __contains__(numbers, 8)
  • the element at index 0 of stack (Python Object Store at time 29) = [2, 4, 6, 8, 10]

then Return Value at time (29 + 1) = stack [ 2, [ 4, [ 6, [ 8, [ 10, [ ] ] ] ] ] ] contains 8

Try stepping through the simulator to see LW Python look for "8" in the list [2, 4, 6, 8, 10].

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments