0

My understanding of this part of sentiments is that I need to open the positive words file and make it all into a list, I thought I could do this with open.readlines, but it isn't working. Can someone let me know what's wrong with my code? Thanks

def __init__(self, positives, negatives):
    """Initialize Analyzer."""
    poslist = open("positive-words.txt").readlines()
    print(poslist)
    # TODO

1 Answer 1

0

we are inside a class in python, one way is to declare a set (not ordered), the way to do it would be the following:

def __init__(self, positives, negatives):
        """Initialize Analyzer."""
        # TODO
        self.positives = set()
        file = open("positive-words.txt", "r")
        for line in file:
            ......
                self.positives.add(line)
        file.close()
2
  • Awesome, just what I was looking for, could you give me any hints on what goes in the for loop?
    – Joel Banks
    Commented Nov 9, 2017 at 23:25
  • According to the specifications, some functions like startswith, strip or rstrip will be of help
    – MARS
    Commented Nov 9, 2017 at 23:36

You must log in to answer this question.

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