Created
August 2, 2016 00:12
-
-
Save LotusChing/f81f0870354108d197652c9b5f55757b to your computer and use it in GitHub Desktop.
words search match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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