I'm trying to get the analyzer function to work and I'm really just not fully understanding what to do and how to do it. I think I need to take each line of the text files and have put into a string. The part I'm confused on is how to actually make it into a string. Thanks for your help, this is what I have so far

def __init__(self, positives, negatives):
    """Initialize Analyzer."""
    self.positives = set()
    file = open("positive-words.txt", "r")
    for line in file:

1 Answer 1


str.lower does not change the string, it returns a lower-cased copy. So self.positives.add(str.lower(line)) would be a way to use it correctly.

In my code, I also added some code to ignore lines starting with ; or whitespace-only, and also strip any whitespaces from the lines.

And use open(positives, "r"), as the file name might be different.

  • Thanks for your help. So does this make each line into a list? If so, what is the name of the list
    – Joel Banks
    Commented Nov 12, 2017 at 0:23
  • You don't have a list in this code, but directly add lines to the set.
    – Blauelf
    Commented Nov 12, 2017 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .