1

this not work well:

a = ['123','567','10', '223', '33']
for item in a:
    if ('5' or '1' or '2') in item:
        print(item)

I want to get any item in which there is at least one match with the numbers 1 or 2 or 5 My version is very cumbersome:

if '5' in item or '1' in item or '2' in item:
  • 1
    Does this answer your question? [How to check if one of the following items is in a list?](https://stackoverflow.com/questions/740287/how-to-check-if-one-of-the-following-items-is-in-a-list) – mkrieger1 Oct 21 '22 at 15:16

1 Answers1

0

You can use any,

a = ['123','567','10', '223']
for item in a:
    if any(i in item for i in ('5','1','2')):
        print(item)
Rahul K P
  • 15,740
  • 4
  • 35
  • 52