Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:25:12+00:00 2026-06-04T14:25:12+00:00

I have a string like: This is such an nice artwork and I have

  • 0

I have a string like:

" This is such an nice artwork"

and I have a tag_list ["art","paint"]

Basically, I want to write a function which accepts this string and taglist as inputs
and returns me the word “artwork” as artwork contains the word art which is in taglist.

How do i do this most efficiently?

I want this to be efficient in terms of speed

 def prefix_match(string, taglist):
        # do something here
     return word_in string
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:25:13+00:00Added an answer on June 4, 2026 at 2:25 pm

    Try the following:

    def prefix_match(sentence, taglist):
        taglist = tuple(taglist)
        for word in sentence.split():
            if word.startswith(taglist):
                return word
    

    This works because str.startswith() can accept a tuple of prefixes as an argument.

    Note that I renamed string to sentence so there isn’t any ambiguity with the string module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have a string like this A. rahul VyAs and i want to remove
I have some extension methods which could be used like this: MyType myObject; string
I have a delimiter string like this: 2,3 which is grabbed from a listbox
I have a string like this: R3(a1b1,a1c1,b2c1), or R3(a1b1,a1c1,b2c1). I want to split it
having another short regex problem. Basically I have a string like such: cn=WSG-AP-LO-COMMON-SITE-APPS,ou=ZFD,ou=SVC,ou=IGH I'm
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have a string like this: String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] I would like
I have a string like this: event name|event description|event type|event date|event time|event details, event
I have a string Like this: MyText (1,151) I would like to get with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.