a = ["leo", "kiki", "eden"]
b = ["eden", "kiki"]
def s(a,b):
zip = []
for a in b:
zip.append(a)
for i in range(len(zip)):
a.remove(zip[i])
return a
print(s(a,b))
I want to delete the list of a and print it out, but when I run it,
Traceback (most recent call last):
File "main.py", line 13, in <module>
print(s(a,b))
File "main.py", line 10, in s
a.remove(zip[i])
AttributeError: 'str' object has no attribute 'remove'
It pops up like this.
I don't understand why it's perceived as str
. Isn't it list
? I don't know why I can't use it.
def s(a,b):
zip = []
for a in b: # <<<< a !
zip.append(a)
for i in range(len(zip)):
a.remove(zip[i])
As the string is assigned to a
in the first for
statement, the list a
entered as a factor is lost.
a = ["leo", "kiki", "eden"]
b = ["eden", "kiki"]
def s(a,b):
return list(set(a) - set(b))
print(s(a,b))
© 2024 OneMinuteCode. All rights reserved.