Python dictionary optimize this script
<p>I have a string like <code>rdb_master_mongodb</code> where <code>rdb_</code> is fixed and <code>master</code> is a database name which can be anything and <code>mongodb</code> can be one among <code>mysql</code>, <code>mongodb</code>, <code>postgres</code>, <code>mssql</code> or <code>bdb</code>. I need to fetch the value for this string from the dictionary which has the value in <code>myDict[master][mongodb]</code>. In order to get this I need to split the string <code>rdb_master_mongodb</code> and get the values of <code>master</code> and <code>mongodb</code>. I can't use split because sometimes the string becomes <code>rdb_master_test_mongodb</code>. Hence I have to use <code>endswith</code> to get the exact key. Howeveer, <code>endswith</code> does not work on a list.</p>

<p>I have to get the matching tuple value from a tuple. Right now I do this like:</p>

<pre><code>import re 
name = 'rdb_master_mongodb'
s = re.sub('rdb_', "", name)
VALID_DB = ('mysql', 'postgres', 'mongodb', 'mssql', 'bdb')
(a, b, c, d, e) = VALID_DB
if s.endswith(a):
   db = a
if s.endswith(b):
  db = b
if s.endswith(c):
  db = c
if s.endswith(d):
  db = d
if s.endswith(e):
  db = e
db_name = re.sub('_'+db, "", s)
print db_name+" is "+db
</code></pre>

<p>Is there a better way to do this?</p>
