Python Forum
Can I check multi condition for 1 item in a easy way?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I check multi condition for 1 item in a easy way?
#1
Hello,
I want to check if 1 item apper in 4 lists
right now this is how I do this:
if item is not None and item is not False and item not in Error_List:
    print(item)
is there an easy \ cleaner way to do this? something like:

is item not in list1 or list2 or list3 
Thanks
Reply
#2
"if not item or item in Error_list" will work, but not "not item" is also true for 0, empty container objects, and blank strings. Have you tried using "any()"?
Reply
#3
can you explain \ show example ? (find if 1 item is in 3 differnets lists)
Thanks ,
Reply
#4
if item and item not in Error_List:
    print(item)
This should work, if item is a NoneType, Boolean or something different which is not in Error_List.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
Examples how to use Python "any"

https://realpython.com/any-python/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove an item from a list contained in another item in python CompleteNewb 19 5,661 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Check all input, easy way! Help pls! bntayfur 2 1,782 Jul-05-2020, 10:58 PM
Last Post: bntayfur
  else condition not called when if condition is false Sandz1286 10 5,840 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 7,894 Jun-01-2020, 06:00 PM
Last Post: penahuse
  Condition check differences and how to organise code? adam2020 4 2,668 May-12-2019, 04:12 PM
Last Post: Yoriz
  looking for a multi item container Skaperen 2 2,048 Apr-15-2019, 04:06 AM
Last Post: Skaperen
  check how many times an item appears in list davidm 8 5,010 Dec-29-2018, 07:49 PM
Last Post: davidm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020