Reputation: 93
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
# above is where I get the error from
load_ws[i+1,4] = str(datatocopy)
else:
continue
The above is part of my codes. I get the error saying TypeError: expected string or bytes-like object.
from datatocopy = final_keys[word]
. Any help?
Upvotes: 0
Views: 152
Reputation: 78
I checked your code and the line you mention throws errors works fine. Here is what I tried :-
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
print("Values : ", datatocopy)
# above is where I get the error from
# load_ws[i+1,4] = str(datatocopy)
else:
continue
And here is the output :
Values : a,b,c,d,b
Values : a,b,c,d,b
Values : s,q,d,f,d,s,d
Values : s,q,d,f,d,s,d
Values : a,q,v,d,s,
Values : a,q,v,d,s,
Upvotes: 1