Quote:
18:28:02 (C): jpez: go!
18:28:01 (C): jpez: and it's in python
18:25:49 (C): jpez: would all match
18:25:46 (C): jpez: bob smith is 1337
18:25:39 (C): jpez: bob is 1337
18:25:33 (C): jpez: smith is 1337
18:25:27 (C): jpez: so
18:25:24 (C): jpez: and i would like to find strings where it's "subject is *"
18:25:02 (C): jpez: so bob smith for example
18:24:56 (C): jpez: also number of words
18:24:38 (C): jpez: i have a subject of arbitrary length and number of characters
18:24:27 (C): jpez: ok
18:28:01 (C): jpez: and it's in python
18:25:49 (C): jpez: would all match
18:25:46 (C): jpez: bob smith is 1337
18:25:39 (C): jpez: bob is 1337
18:25:33 (C): jpez: smith is 1337
18:25:27 (C): jpez: so
18:25:24 (C): jpez: and i would like to find strings where it's "subject is *"
18:25:02 (C): jpez: so bob smith for example
18:24:56 (C): jpez: also number of words
18:24:38 (C): jpez: i have a subject of arbitrary length and number of characters
18:24:27 (C): jpez: ok
this won't handle generic whitespaciness, so I'm assuming you have formatted input. otherwise, use re.split(thing,'\s+') or something of that sort. you have to import re. the arguments may be in the wrong order, but you can google it.
this will handle "Bob Smith is 1337", "Bob is 1337" and "Smith is 1337" if subject is "Bob Smith" but not "Bobby Smith is 1337" if the subject is "Bobby Tom Smith"
if you want to be able to do that, you need loop
Code:
def jpezFunction(subject, sentence):
firstHalf = sentence.split(" is ")[0]
return firstHalf in subject
the smarter version follows
Code:
def jpezFunction(subject, sentence):
subjects = subject.split(" ")
firstHalf = sentence.split(" is ")[0]
possibleSubjects = firstHalf.split(" ")
if firstHalf in subject:
return True
else:
for ps in possibleSubjects:
if ps not in subjects:
return False
return True
here's the list comprehension version, which is much cooler. you can make it faster if you pull those splits out and make variables from them, but one line functions look cooler
Code:
def jpezFunction(subject, sentence):
return False not in [(ps in subject.split(" ") for ps in sentence.split(" is ")[0].split(" ")]