I assume that I have the following problem: I create a list for the banned words and although a list with the text input. Then I want to compare both list.
But when I create the list of the user input - I think - it stores the complete string and index 0 of the list and afterwards I cant compare both lists.
I made a screenshot of how the list look like, after I stored the string in it:
And here is my code:
from cs50 import get_string
from sys import argv
def main():
if len(argv) != 2:
while True:
print("Enter only filename of dictionary")
if len(argv) == 2:
break
filename = argv[1]
try:
file = open("{}".format(filename), "r")
except IOError:
print("Could not open file!")
bannedList = []
for line in file:
s = line.splitlines()
bannedList.append(s)
file.close()
input = get_string("Enter your text: ")
inputList = [input.split()]
rightList = ""
for word in input:
if word in bannedList:
rightList += ("*" * len(word)) + " "
else:
rightList += word + " "
print(rightList.strip())
if __name__ == "__main__":
main()
Thanks for your help!! :)