I have list as follows
string = ['I went to work but got delayed at other work and got stuck in a traffic']
Now I want a output like as follows
stirng_seq = [(I, went), (went,to), (to,work), (work,but).....(in,a),(a,traffic)]
To clarify, I want a list of tuples where words are sequential.
My approach so far,
words = list(set(word.lower() for t in string for word in t.split()))
inv_txt = [(i,j) for i,j in zip(words[:-1],words[1:])]
However this is producing all combination of word pairs which I do not want. Like
[('went', 'got'), ('got', 'at'), ('at', 'and'), ('and', 'stuck'), ('stuck', 'traffic'), ('traffic',
'but'), ('but', 'in'), ('in', 'other'), ('other', 'work'), ('work', 'to'), ('to', 'i'), ('i',
'delayed'), ('delayed', 'a')]
Any clue on this? Even itertools.permutations()
seems not to have worked.