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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:19+00:00 2026-06-04T17:04:19+00:00

I am trying to implement to search for a value in Python dictionary for

  • 0

I am trying to implement to search for a value in Python dictionary for specific key values (using regular expression as a key).

Example:

I have a Python dictionary which has values like:

{'account_0':123445,'seller_account':454545,'seller_account_0':454676, 'seller_account_number':3433343}

I need to search for values whose key has ‘seller_account’? I wrote a sample program but would like to know if something can be done better. Main reason is I am not sure of regular expression and miss out something (like how do I set re for key starting with ‘seller_account’):

#!usr/bin/python
import re
my_dict={'account_0':123445,'seller_account':454545,'seller_account_0':454676, 'seller_account_number':3433343}

reObj = re.compile('seller_account')

for key in my_dict.keys():
        if(reObj.match(key)):
                print key, my_dict[key]

~ home> python regular.py

seller_account_number 3433343
seller_account_0 454676
seller_account 454545
  • 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-04T17:04:20+00:00Added an answer on June 4, 2026 at 5:04 pm

    If you only need to check keys that are starting with "seller_account", you don’t need regex, just use startswith()

    my_dict={'account_0':123445,'seller_account':454545,'seller_account_0':454676, 'seller_account_number':3433343}
    
    for key, value in my_dict.iteritems():   # iter on both keys and values
            if key.startswith('seller_account'):
                    print key, value
    

    or in a one_liner way :

    result = [(key, value) for key, value in my_dict.iteritems() if key.startswith("seller_account")]
    

    NB: for a python 3.X use, replace iteritems() by items() and don’t forget to add () for print.

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

Sidebar

Related Questions

I'm trying to implement a system where I'll have key-value structure pairs. They will
I am trying to implement an efficient algorithm for nearest-neighbour search problem. I have
I'm trying to implement a search method, which returns a index of a object
I'm trying to implement a real-time updating search bar which updates a TreeView when
I am trying to implement pagination in my search results with Yii. I have
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
I have a <f:viewParam> driven search screen. I am trying to implement it to
I'm trying to implement a simple search, using LIKE in my SQL statement: Using
I am trying to implement a djapian based full text search for searching user
I've been trying to implement a delete function for a Binary Search Tree but

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.