1

Say I have a list:

['[name]\n', 'first_name,jane\n', 'middle_name,anna\n', 'last_name,doe\n', '[age]\n', 'age,30\n', 'dob,1/1/1988\n']

How could I check if the strings 'jane', 'anna' and 'doe' are ALL contained in an element of the list.

Mohamed AL ANI
  • 2,012
  • 1
  • 12
  • 29

1 Answers1

3

For each name you can use any to see if it is contained in any of the strings in the list, then make sure this is true for all of the names

>>> data = ['[name]\n', 'first_name,jane\n', 'middle_name,anna\n', 'last_name,doe\n', '[age]\n', 'age,30\n', 'dob,1/1/1988\n']
>>> names = ['jane', 'anna', 'doe']
>>> all(any(name in sub for sub in data) for name in names)
True
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218