Check if a string ends with a decimal in Python 2
<p>I want to check if a string ends with a decimal of varying numbers, from searching for a while, the closest solution I found was to input values into a tuple and using that as the condition for endswith(). But is there any shorter way instead of inputting every possible combination?</p>

<p>I tried hard coding the end condition but if there are new elements in the list it wont work for those, I also tried using regex it returns other elements together with the decimal elements as well. Any help would be appreciated</p>

<pre><code>list1 = ["abcd 1.01", "zyx 22.98", "efgh 3.0", "qwe -70"]

for e in list1:
    if e.endswith('.0') or e.endswith('.98'):
        print 'pass'
</code></pre>

<p>Edit: Sorry should have specified that I do not want to have 'qwe -70' to be accepted, only those elements with a decimal point should be accepted</p>

<p>I think this will work for this case:</p>

<pre><code>regex = r"([0-9]+\.[0-9]+)"

list1 = ["abcd 1.01", "zyx 22.98", "efgh 3.0", "qwe -70"]

for e in list1:
    str = e.split(' ')[1]
    if re.search(regex, str):
       print True #Code for yes condition
    else:
       print False #Code for no condition
</code></pre>

python list ends-with