I have two lists: A and B. I want to create a third list, which is 1 if the corresponding entry in has an entry in list B at the end of the line and 0 otherwise.
A = ['Mary Sue', 'John Doe', 'Alice Stella', 'James May', 'Susie May']
B = ['Smith', 'Stirling', 'Doe']
I want the list to understand what will produce the result
[0, 1, 0, 0, 0]
Keep in mind that this is a specific case of a more general problem. Elements in can have arbitrary empty space and contain an arbitrary number of words in them. Similarly, elements in B can have an arbitrary number of words. for instance
A = [' Tom Barry Stirling Adam', 'Maddox Smith', 'George Washington Howard Smith']
B = ['Washington Howard Smith', 'Stirling Adam']
must return
[1, 0, 1]
So far I have the following
[1 if y.endswith(x) else 0 for x in B for y in A]
, , 0 1 A [i], B [j]. , , .