1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python dictionary search values for keys using regular expression

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm searching for values in this Python dictionary using regular expressions as keys:

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


    I search for values whose key has seller_account; how do I set a regular expression for keys starting with seller_account?

    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

    Continue reading...

Compartilhe esta Página