Let’s say I have a list named
mylist = []
This list contains sentences from a file. My question is:
-
Is there a way I can add each element of mylist into separate sets?
-
If it can be done, then how to add to different set?
My code:
mylist = []
wordlist = open('data.txt', 'r').read().split()
ngrams = [wordlist[i:i+5] for i in range(len(wordlist)-4)]
mylist.append(ngrams)
print mylist
Some edits:
My output looks like this
[('hello', 'there')]
[("I'm", 'using'), ('using', 'python'), ('python', 'for'), ('for', 'the'), ('the', 'first'), ('first', 'time.')]
What I want to do is add each of the bigram into separate sets.
I might be just misunderstanding your question, yet… are you trying any of these two?
Creating new sets from bigrams:
Adding bigrams to existing sets: