0

I have a list of strings that looks like this: ['ban*', 'c*rr*r', 'pl*s', pist*l ]. I want to check if those strings have matching equivalents in another list of strings which is the following:

['banner', 'bannana', ban, 'carrer', 'clorror', 'planes', 'plots']

Comparing first string from the list I have'banner' and 'bannana' and that would mean that there is a word that is matching that string ("ban*") So the '*' means that there can be one or more letters in that word.

Alex T
  • 3,529
  • 12
  • 56
  • 105

1 Answers1

2

Try this fnmatch approach

import fnmatch
lst = ['banner', 'bannana', 'ban', 'carrer', 'clorror', 'planes', 'plots']
f1 = fnmatch.filter(lst, 'ban*')
print (f1)

Output

['banner', 'bannana', 'ban']
Richard Rublev
  • 7,718
  • 16
  • 77
  • 121