Basic Sentiment Analysis

Learn how to perform basic sentiment analysis using Python.

  1. Create sentiment dictionary:
sentiment = {
    'good': 1,
    'bad': -1,
    'great': 2,
    'terrible': -2
}
  1. Analyze text:
def analyze(text):
    words = text.lower().split()
    return sum(sentiment.get(word, 0) for word in words)
  1. Test analysis:
print(analyze("This is a great day!"))

Read more: Sentiment Analysis