fork download
  1. strlist = ['the', 'the', 'boy', 'happy', 'boy', 'happy']
  2. print(dict(((string, set(i for i,w in enumerate(strlist) if w == string)) for string in strlist)))
  3.  
Success #stdin #stdout 0.15s 10256KB
stdin
Standard input is empty
stdout
{'boy': {2, 4}, 'the': {0, 1}, 'happy': {3, 5}}