0

So I'm currently working in similarities and after making index.html to be able to see which functions work, I started working in lines. When passing in this function with the compare1 (1).c and compare2 (2).c files I get the error:

TypeError: decoding to str: need a bytes-like object, list found

I researched what was the problem and tried ASCII encoding my list but it didn't work. Here is my code:

from nltk.tokenize import sent_tokenize

def lines(a, b): #Return lines in both a and b

list_a = a.splitlines()
list_b = b.splitlines()
final_list = []

for x in list_a:
    if x in list_b:
        if x not in final_list:
            final_list.append(x)

return [final_list]

and here is my code when I tried ASCII encoding:

from nltk.tokenize import sent_tokenize

def lines(a, b): #Return lines in both a and b

list_a = a.splitlines()
list_b = b.splitlines()
final_list = []

for x in list_a:
    if x in list_b:
        if x not in final_list:
            final_list.append(x)

for x in final_list:
    x = x.encode("ASCII"):

return [final_list]

Any ideas as to why this happens and how to fix it? All help is appreciated.

1

The only thing I see wrong with your first one is that you are returning a list inside of a list return [final_list] instead of returning the list itself with return final_list

That str object error looks more to do with the filenames you are passing to the function. Do they have spaces and parentheses as you are showing? Try passing 2 files that don't have that in their names.

You must log in to answer this question.

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