-2

I have a list of string that contains values like this:

  • 'abc_def'
  • '{xyz_abc}'
  • '{www-ABC-zzz}'

I wish to find partial text match in my list using the any keyword:

result = any('abc' in w for w in list)

How can I find all the matching while ignoring upper case of lower case and yet find partial text match?

9
  • "all the matching" and any are about different things Commented Oct 2, 2023 at 8:53
  • @RomanPerekhrest So I can find all, not any? Commented Oct 2, 2023 at 8:54
  • What exactly do you want to be the output? Commented Oct 2, 2023 at 8:54
  • True if item in my list contain ABC or abc, False otherwise Commented Oct 2, 2023 at 8:56
  • If that's what you want, then I would just add a lower() call so that the case is forced to lower: result = any("abc" in w.lower() for w in list1) Commented Oct 2, 2023 at 8:56

1 Answer 1

1
r = [w for w in list if 'abc' in w.lower()]

if you want to return the list of matched string

r = [if 'abc' in w.lower() for w in list ]

or a list of booleans.

Regular expression (see package re from the standard) or unix pattern matching (see package fnmatch) might be required for more sophisticated cases

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.