Mary Ruth Winston - 4 months ago 34

Python Question

I am working on a whitelist project as part of a training course. My program is split into three sections: a whitelist, the user's input, and a third array that counts the instances that a whitelist word appears in the users input. All three sections have been converted into arrays. For example, if my whitearray contains the words (good, talented, special) and my user inputs ("My best friend is a really good flute player. My good friend Celia isn't as skillful."), I should be able to print a result: good 2

My code:

`import numpy`

whitefile = open('whitefile.txt', 'r')

check = raw_input("Hi! Please enter a string and we will see which words are in the whitefile! Enter here: ")

elementA = 0

check = check.lower()

loopEr = 0

whiteList = []

for line in whitefile:

myTokens = line.split( )

whiteList.append(myTokens)

inpList = check.split()

whiteArray = numpy.array(whiteList).astype(numpy)

#numpy.reshape(inpArray, (2,3))

inpArray = numpy.array(inpList).astype(numpy)

lenwhitefile = len(whiteList)

whiteListCounter = numpy.zeroes((1, lenwhitefile).dtype = numpy.float64)

for i in range(0, len(inpList)-1):

if inpArray[i] in whiteArray:

while i in range(0, lenwhiteList):

if inpArray[i] == whiteArray[loopEr]:

Error Received:

`File "whitelist.py", line 21`

whiteListCounter = numpy.zeroes((1, lenwhitefile).dtype = numpy.float64)

SyntaxError: keyword can't be an expression

How can I fix this?

Answer

I think you have 2 issues:

`zeros`

instead of`zeroes`

`,dtype`

rather than`.dtype`

`whiteListCounter = numpy.zeros((1, lenwhitefile), dtype = numpy.float64)`