2
Could someone help me with this question?
def fileRead(file):
txt = open(file)
print(txt.read())
def index(filepath, keywords):
with open(filepath) as f:
for lineno, line in enumerate(f, start=1):
matches = [k for k in keywords if k in line]
if matches:
result = "{:<15} {}".format(','.join(matches), lineno)
print(result)
#Programa Principal
fileRead('cores.txt')
fileRead('carta.txt')
index('cores.txt', ["amarelo"])
index('carta.txt', ["azul"])
index('carta.txt', ["verde"])
What’s the problem with the code? if possible edit the question and explain what the purpose of it, and also post a snippet of a file and tell what you expect to get from it!
– stderr
@stderr I have 2 files . txt that need to be read and produce the set of words contained in it .... then take as parameter the set of reference words and the name of the search file, and write, in the default output, the word and its placement in the search file if it is in the reference set. Ex.: Input : letter.txt / Output: ("blue", 3, 5) But ... I can only print the text (+) yellow 1 blue 3 green 4
– ABSoares