masterp
masterp

Reputation: 11

Check if all elements of a list are in a big single element list

List1 = ['error please notify us immediately services page com page run policy report date time est valuation date 02 29 2020 currency accident state due to regulatory considerations some of the content contained in this report financial information run additional reports using']

List2 = ['accident state', 'additional reports','contained']

In the above case, I would like to return True, since accident date, additional reports and contained in List2 are all found in List1. Note: I cannot split List1 along spaces.

My attempt:

for i in s[0]:
     if all(item in [i] for item in ['accident state','additional reports','contained']):
          print(True)
     else:
          print(False)

Upvotes: 0

Views: 54

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 118021

Your generator expression used in all would be

>>> all(i in List1[0] for i in List2)
True

Though I'd question if List1 should instead just a string instead of a list with just one element.

Upvotes: 1

Related Questions