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 8599013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:17:45+00:00 2026-06-12T01:17:45+00:00

Parsed the IANA subtag (see Cascaded string split, pythonic way ) and made a

  • 0

Parsed the IANA subtag (see Cascaded string split, pythonic way) and made a list of 8600 tags:

tags= ['aa',
       'ab',
       'ae',
       'af',
       'ak',
       'am',
       'an',
       'ar',
       # ...

I want to check for example mytag="ro" if is in the list:
what is the fastest way to do that:

First solution:

if mytag in tags:
    print "found"

Second solution:

if mytag in Set(tags):
    print "found"

Third solution: Transform the list in a big string like: '|aa|ab|ae|af|ak|am|an|ar|...' and then see if string is in another string:

tags = '|aa|ab|ae|af|ak|am|an|ar|...'
if mytag in tags:
    print "found"

Is there another way? Which is the fastest, is this already measured, if not how can I benchmark myself (shoul I take a random element from the list or should I take the last and then test it, can someone provide python code for a ‘chronometer’)?

  • 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-12T01:17:46+00:00Added an answer on June 12, 2026 at 1:17 am

    As I don’t have access to the original string, any test would be biased. However, you asked for a chronometer ? Check the timeit module, designed to time some code snippets.

    Note that if you use IPython, %timeit is a magic function that makes it a breeze to time the execution of a function, as illustrated below.

    Some comments

    • you should replace Set by set…
    • construct your set and long string before running any test
    • Taking a random element from your tags list is the way to go indeed.

    As an example of use of %timeit in IPython:

    tags = ['aa','ab','ae','af','ak','an','ar']
    tags_set = set(tags)
    tags_str = "|".join(tags)
    
    %timeit 'ro' in tags
    1000000 loops, best of 3: 223 ns per loop
    %timeit 'ro' in tags_set
    1000000 loops, best of 3: 73.5 ns per loop
    %timeit 'ro' in tags_str
    1000000 loops, best of 3: 98.1 ns per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive parsed a text file into a List<string> object and the test file contains
I've parsed several strings into Enum flags but can't see a neat way of
My list view is parsed from a online resource, but i cant get the
I want to clean up some parsed text such as \n the said \r\n\r\n\r\n
My example non-parsed data is 8$154#3$021308831#7$NAME SURNAME#11$2166220160#10$5383237309#52$05408166# I want to parse data that is
In my application I parsed the data through NSXMLParser and made separate class to
-- I just parsed a big file and I created a list containing 42.000
I have parsed a java.util.Date from a String but it is setting the local
I have an RSS feed parsed into a list view in my app. I'm
I have parsed a given CSS file/string into a JSON object like so: {

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.