pattern matching with multiple lists

C

Chad Kellerman

Greetings,
     I have some code that I wrote and know there is a better way to
write it.  I wonder if anyone could point me in the right direction
on making this 'cleaner'.

     I have two lists:   liveHostList = [ app11, app12, web11, web12, host11 ]
                                    stageHostList      = [  web21,
web22, host21, app21, app22 ]

     I need to pair the elements in the list such that:
    app11  pairs with app21
    app12 pairs with app22
    web11 pairs with web21
    web12 pairs with web22
    host11pairs with host21

    each time I get the list I don't know the order, and the lists
will grow over time.  (hosts will be added in pairs.  app13 to
liveHostList and app23 to stageHostList, etc)


Anyways this is what I have.  I think it can be written better with
map, but not sure.  Any help would be appreciated.

import re
for liveHost in liveHostlist:

    nameList = list(liveHost)
    clone    = nameList[-1]
    di       = nameList[-2]
    generic  = liveHost[:-2]

    for stageHost in stageHostList:
        if re.match( generic + '.' + clone, stageHost ):
            print "Got a pair: " + stageHost + liveHost

Thanks again for any suggestions,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top