BlackBear > , - . , .
. . -, .
string = "My name is Andrew, I am pretty awesome"
choices = [['andrew', 'name', 'awesome'], ['andrew', 'designation', 'awesome']]
1
in
. in
Boyer-Moore C .
>>> [c for c in choices if all(y in string.lower() for y in c)]
[['andrew', 'name', 'awesome']]
, . -, nitpick; string.lower()
, -
v = string.lower()
%timeit [c for c in choices if all(y in v for y in c)]
1000000 loops, best of 3: 2.05 µs per loop
2
re.split
+ set.issuperset
;
>>> import re
>>> [c for c in choices if set(re.split('\W', string.lower())).issuperset(c)]
[['andrew', 'name', 'awesome']]
re.split
, - .
, set
. -
v = set(re.split('\W', string.lower()))
%timeit [c for c in choices if v.issuperset(c)]
1000000 loops, best of 3: 1.13 µs per loop
, , . , . , - , , .