Have a data in such format in .txt file:
UserId WordID 1 20 1 30 1 40 2 25 2 16 3 56 3 44 3 12
while you might be more interested in doing it in pandas depending on your purpose, the numpy way would be:
pandas
userid,wordid = np.loadtxt('/data/file.txt',skiprows=1,unpack=True) #example use: mylist = [] for uid in np.unique(userid): mylist.append(wordid[userid==uid])