I have a problem:
list = [1,2,3,4,5]
a= 3
if a==[item for item in list]:
print(sth)
why the program never print? thanks...
I have a problem:
list = [1,2,3,4,5]
a= 3
if a==[item for item in list]:
print(sth)
why the program never print? thanks...
You're comparing an integer to a list, which will never return True as they are different types. Note that [item for item in list] is exactly the same as just saying list.
You're probably wondering if 3 is in the list; so you can do:
if a in list:
print(sth)
Or even:
if any(a == item for item in list):
print(sth)
(Although you really should just use the first option. I only put the second option in as it looks similar to your example :p)
As a side note, you shouldn't be naming lists list, or dictionaries dict, as they are built-in types already, and you're just overriding them :p.