Hot answers tagged


Is the problem that you have hardcoded the input file to "banned.txt"? From the specification: Accepts as its sole command-line argument the name (or path) of a dictionary of banned words (i.e., text file). Opens and reads from that file the list of words stored therein, one per line, and stores each in a Python data structure for later access. ...


Technical aspects of your question: When posting Python code, make sure indentation is preserved. This looks like you took the code by reddit user /u/randolph_777 and dumped it here, making it pass through two markdown interpreters. On both platforms, a code block is traditionally marked by four spaces in front of every line. On Stackexchange, in the editor, ...


Firstly, the method split returns a list; and as per the line inputList = [input.split()] your're enclosing the returned list within another which yields the nested list. Secondly, you might want to consider revising the line s = line.splitlines() as the method splitlines breaks the string at line boundaries (i.e. \n) which might not what you intended since ...


The block of code that needs to be changed is as mentioned below after the line 15: save the file name from the command line argument into a variable called banned_text banned_text = argv[1] use the variable name in the below file open command with open(banned_text, "r") as f: With rest of the code as it is, program works absolutely fine:)

Only top voted, non community-wiki answers of a minimum length are eligible