0

If I have such a list of tuples:

train = [('pad thai', 'FOOD#QUALITY'),
 ('Ginger House', 'RESTAURANT#GENERAL'),
 ('fried dumplings', 'FOOD#QUALITY'),
 ('Chinese restaurant', 'RESTAURANT#GENERAL'),
 ('customer service', 'SERVICE#GENERAL'),
 ('management', 'SERVICE#GENERAL')]

I can use freq = nltk.ConditionalFreqDist((a, category) for a, category in train) to get the frequencies of whole phrase in a category, but if I want to store just the frequencies of unigrams, how would I do this, preferably in a list comprehension? I have come across this solution: Remove uni-grams from a list of bi-grams which is helpful, but would like something more concise if possible.

Community
  • 1
  • 1
user3058703
  • 571
  • 1
  • 8
  • 22
  • Please make an attempt, then if you get stuck come back and ask questions. – wwii Apr 24 '17 at 19:17
  • The first answer in the question you link to is pretty concise-- three lines of code. If it really doesn't meet your needs, please edit your question to explain why. – alexis Apr 24 '17 at 19:30

0 Answers0