On Wed, Mar 19, 2008 at 3:56 PM, Tim Michelsen &lt;<a href="mailto:timmichelsen@gmx-topmail.de">timmichelsen@gmx-topmail.de</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
m = 0<br>
cm = 0<br>
mm = 0<br>
## first list item<br>
if first.endswith(&quot;m&quot;,-1):<br>
 &nbsp; &nbsp; m = first.strip(&quot;m&quot;)<br>
elif first.endswith(&quot;cm&quot;,-2):<br>
 &nbsp; &nbsp; cm = first.strip(&quot;cm&quot;)<br>
elif first.endswith(&quot;mm&quot;,-2):<br>
 &nbsp; &nbsp; mm = first.strip(&quot;mm&quot;)<br>
else:<br>
 &nbsp; &nbsp; print &#39;Wrong unit!&#39;<br>
## second list item<br>
if second.endswith(&quot;m&quot;,-1):<br>
 &nbsp; &nbsp; m = second.strip(&quot;m&quot;)<br>
elif second.endswith(&quot;cm&quot;,-2):<br>
 &nbsp; &nbsp; cm = second.strip(&quot;cm&quot;)<br>
elif second.endswith(&quot;mm&quot;,-2):<br>
 &nbsp; &nbsp; mm = second.strip(&quot;mm&quot;)<br>
else:<br>
 &nbsp; &nbsp; print &#39;Wrong unit!&#39;<br>
## third list item<br>
if second.endswith(&quot;m&quot;,-1):<br>
 &nbsp; &nbsp; m = second.strip(&quot;m&quot;)<br>
elif second.endswith(&quot;cm&quot;,-2):<br>
 &nbsp; &nbsp; cm = second.strip(&quot;cm&quot;)<br>
elif second.endswith(&quot;mm&quot;,-2):<br>
 &nbsp; &nbsp; mm = second.strip(&quot;mm&quot;)<br>
else:<br>
 &nbsp; &nbsp; print &#39;Wrong unit!&#39;<br>
</blockquote><div><br>Since they all end in &quot;m&quot;, if you do that test first it catches all three cases.&nbsp; It&#39;s almost as if you put the &quot;else&quot; before the &quot;if&quot;.<br>Regexes are a wonderful thing to learn - do that by all means - but the simplest thing would be to reverse the order of your tests: check against &quot;mm&quot; first, then &quot;cm&quot;, THEN &quot;m&quot;.<br>
<br>To clarify - regexes are probably the best solution for your current program, but as a general rule it helps to look at tests like this from a different angle.<br></div></div><br>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a>