>>> alist = [['its', 'all', 'ball', 'bearings', 'these', 'days'],
... ['its', 'all', 'in', 'a', 'days', 'work']]
>>> aset = {'its', 'all', 'ball', 'bearings', 'these', 'days', 'in', 'a', 'work'}
>>> {x: {alist.index(y) for y in alist if x in y} for x in aset}
{'a': set([1]), 'all': set([0, 1]), 'ball': set([0]), 'these': set([0]), 'bearings': set([0]), 'work': set([1]), 'days': set([0, 1]), 'in': set([1]), 'its': set([0, 1])}
Also you can use enumerate
and use list to be value will make the result clearer:
>>> {x: [i for i, y in enumerate(alist) if x in y] for x in aset}
{'a': [1], 'all': [0, 1], 'ball': [0], 'these': [0], 'bearings': [0], 'work': [1], 'days': [0, 1], 'in': [1], 'its': [0, 1]}