0

I am looking for a way to filter a list if a value is in a string.

filter_object = list(filter(lambda a: f_val in a, f_Results)) works well except that it is case sensitive.

3
  • Can you provide some sample input and expected output? Jul 13, 2021 at 22:02
  • f_Results = ["Abc", "abc", "bac", "Bcc"] # f_Val = "A" # Output: ["Abc", "abc", "bac"] I came across casefold, but I was using it wrong. ie list(filter(lambda a: f_val.casefold() in a, self.f_Results)) Unmitigated's answer got my expected results.
    – cmccall95
    Jul 13, 2021 at 22:23

1 Answer 1

2

You can use str.casefold.

filter_object = list(filter(lambda a: f_val.casefold() in a.casefold(), f_Results))
1
  • casefold is the right answer... I'll reopen if you want - there are some casefold answers in those dupes.
    – wwii
    Jul 13, 2021 at 22:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.