Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what can i do to find the sentence that only contains 'take'?

i want to find all the sentence with the word ‘take’ in this list (x), but one of output is ‘Own your mistakes before the Council’. What can I do if I only want the sentence containing ‘take’ instead of some words that have take inside? Thank you!!

this is my code:

x =['Own your mistakes before the Council,', "You guys know I wouldn't take you on a job you couldn't handle, right?", "Maybe just don't take Powder next time.", "You don't understand what's at stake.", 'You may take your son home, Mrs. Talis,', '- Did they take anything dangerous?', 'Do whatever it takes.', "I'll take the strongest shit you got."]
for i in x:
    if 'take'in i:
        print(i)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add spaces around "take", so " take ", or spilt the lines and check if it contains "take". As explained by @SUTerliakov, my first suggestion won’t work all the time.

This is what the code might look like for my second suggestion.

sentences =['Own your mistakes before the Council,', "You guys know I wouldn't take you on a job you couldn't handle, right?", "Maybe just don't take Powder next time.", "You don't understand what's at stake.", 'You may take your son home, Mrs. Talis,', '- Did they take anything dangerous?', 'Do whatever it takes.', "I'll take the strongest shit you got."]

for sentence in sentences:
    words = sentence.lower().split()
    if "take" in words:
        print(sentence)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading