superpollo ha scritto:
timo verbeek ha scritto:
I'm planning to create a human word program
A human inputs a string
"Give me the weather for London please."
Then I will strip the string.
"weather for london"
Then I get the useful information.
what:"weather" where:"london"
After that I use the info.

I need help with getting the useful information how do I get the place
if I don't now how long the string is?


 >>> query = "Give me the weather for London please."
 >>> what = query.strip("Give me the ").split()[0]
 >>> where = query.strip("Give me the " + what + " for ").split()[0]
 >>> print what, where
weather London
 >>>

maybe better not with strip, fot it might not do what i intended (see docs); maybe preferable to use "partition" method:

>>> query = "Give me the weather for London please."
>>> what  = query.partition("Give me the ")[2].split()[0]
>>> where = query.partition(" for ")[2].split()[0]
>>> print what, where
weather London
>>>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to