Suppose I have an ordered list for reference (in the example of length 10):
ref = ["tom", "was", "playing", "ball", "in", "the", "garden", "with", "his", "friends"]
And I have a list of 3 items:
words = ["ball", "garden", "friends"]
I want to convert the above ref
list to a list of ones and zeros like so.. If t
is in the sequence of strings, we should put a 1
at the i-th position of the output vector, otherwise it should be 0
:
Output:
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1]
Can I do this using a one liner?