I was wondering how you define a funtion which a phrase and two words are inputted and the output is the part of the prhase between the two words. Do you convert the string to a list?? I would apprecitate any help.
Dart82 0 Newbie Poster
Recommended Answers
Jump to PostYes, I'd probably start breaking the sentence into a list of words. Two problems come to mind: (1) Punctuation would need to be trimmed from the end of each word (but possibly need to be remembered in case the punctuated word(s) are part of the output); (2) Individual words can …
Jump to Postcan you give a living example?
For me I don't understand what you are exactly saying! I don't want to redefine it
Jump to PostI posted to a similar thread recently, but I can't remember where. The following will preserve punctuation:
from string import punctuation as stuff def words_between(s, first, second): # return the words between first and second words words = [word.lower() for word in s.split()] # catch error if …
Jump to PostAndy,
No forgiveness necessary. Doing exercises like this is a good way to learn. That's one reason I am doing it.
All 16 Replies
BearofNH 104 Posting Whiz
Dart82 0 Newbie Poster
Andymoore88 0 Newbie Poster
Andymoore88 0 Newbie Poster
Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster
Andymoore88 0 Newbie Poster
bvdet 75 Junior Poster
Andymoore88 0 Newbie Poster
bvdet 75 Junior Poster
Stefano Mtangoo 455 Senior Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Stefano Mtangoo 455 Senior Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Stefano Mtangoo 455 Senior Poster
Dart82 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.