Only Keep Certain Words In A String Python
I was wondering if there was a way to strip away text that isn't the text I needed. I need to remove all text from a screenshot that isn't "loud noises". I've searched all over, but I haven't found an answer. My code:
if "loud noises" in text: print(text) else: pass
I need a way to only display the text "loud noises", and nothing else. (it's a long story)
what you could do is:
def getWord(idx,word,get): try: total = 0 for i in range(len(get)): if word[idx + i] == get[i]: total += 1 if total == len(get): return True else: return False except IndexError: # out of range return text = "I make loud noises" newtext = "" for idx in range(len(text)): if getWord(idx,text,"loud noises"): newtext += "loud noises" print(newtext)
It accomplishes what you're thinking of, and could be used as mehtod.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module