1

I am reading python code like below. But I can not understand lambda x, y: x | y mean. (set(list(chain.from_iterable(s)) + q + a) for s, q, a in data)) looks complicated, but it is just a vocabulary list like ['to', 'the', 'who'].

# ex) data[0]
#     ([[s1], [s2]], [q], [a]])
#     ([['mary', 'moved', 'to', 'the', 'bathroom'], ['john', 'went', 'to', 'the', 'hallway']], ['where', 'is', 'mary'], ['bathroom'])
vocab = sorted(reduce(lambda x, y: x | y, (set(list(chain.from_iterable(s)) + q + a) for s, q, a in data)))

https://github.com/domluna/memn2n/blob/master/single.py#L36

To be sure, I printed x and y. But I have no idea what these are. What do x and x|y mean?

reduce(lambda x, y: print(x, type(x), "---", y, type(y)), (set(list(chain.from_iterable(s)) + q + a) for s, q, a in data))
# None <class 'NoneType'> --- {'where', 'kitchen', 'bathroom', 'the', 'sandra', 'travelled', 'daniel', 'bedroom', 'back', 'went', 'journeyed', 'office', 'moved', 'hallway', 'garden', 'is', 'john', 'to'} <class 'set'>
jef
  • 3,890
  • 10
  • 42
  • 76

0 Answers0