[Answer]-Match block of text against multiple rows

1👍

Let’s say that your artists are a list of tuples containing their id and full name (If you have the artists in another structure you can easily convert it).

artists = [ (1, 'Joe Bloggs'), (2, 'Peter Smith'), (3, 'Jane Doe'), (4, 'Benjamin') ]
t = 'Joe Bloggs\'s dog is called Benjamin. Peter Fuller and John Doe are two unkown persons.'

def findArtists (artists, text):
    return [aid for aid, name in artists if name in text]

print (findArtists (artists, t) )

Leave a comment