Skip to content

Instantly share code, notes, and snippets.

@LotusChing
Created August 2, 2016 00:12
Show Gist options
  • Save LotusChing/f81f0870354108d197652c9b5f55757b to your computer and use it in GitHub Desktop.
Save LotusChing/f81f0870354108d197652c9b5f55757b to your computer and use it in GitHub Desktop.
words search match
collection = ['django_migrations.py',
'django_admin_log.py',
'main_generator.py',
'migrations.py',
'api_user.doc',
'accounts.txt'
]
import re
def LotusFinder(user_input, collection):
suggection = []
pattern = '.*?'.join(user_input)
regex = re.compile(pattern)
for item in collection:
match = regex.search(item)
if match:
suggection.append((len(match.group()), match.start(), item))
return [x for _, _, x in sorted(suggection)]
print(LotusFinder('mig', collection))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment