Skip to content

Instantly share code, notes, and snippets.

@octoparse
Created April 16, 2019 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save octoparse/f148e81f4c8f61d16195ca231d37eb53 to your computer and use it in GitHub Desktop.
Save octoparse/f148e81f4c8f61d16195ca231d37eb53 to your computer and use it in GitHub Desktop.
import re
import json
with open('positive.txt') as f:
p_txt = f.read()
p_txt = re.sub('[,\.()":;!@#$%^&*\d]|\'s|\'', '', p_txt)
p_list = p_txt.replace('\n',' ').replace(' ',' ').lower().split(' ')
# test if cool is in the list
print 'cool is in the postive list: ', 'cool' in p_list
with open('negative.txt') as f:
n_txt = f.read()
n_txt = re.sub('[,\.()":;!@#$%^&*\d]|\'s|\'', '', n_txt)
n_list = n_txt.replace('\n',' ').replace(' ',' ').lower().split(' ')
# test if abrade is in the list
print 'abrade is in the negative list: ', 'abrade' in n_list
# test if cool is in the list
print 'cool is in the negative list: ', 'cool' in p_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment