Checking if an ISBN number is correct
<p>I'm given some ISBN numbers e.g. <code>3-528-03851</code> (not valid) , <code>3-528-16419-0</code> (valid). I'm supposed to write a program which tests if the ISBN number is valid.</p>

<p>Here' my code:</p>

<pre><code>def check(isbn):
    check_digit = int(isbn[-1])
    match = re.search(r'(\d)-(\d{3})-(\d{5})', isbn[:-1])

    if match:
        digits = match.group(1) + match.group(2) + match.group(3)
        result = 0

        for i, digit in enumerate(digits):
          result += (i + 1) * int(digit)

        return True if (result % 11) == check_digit else False

    return False
</code></pre>

<p>I've used a regular expression to check a) if the format is valid and b) extract the digits in the ISBN string. While it seems to work, being a Python beginner I'm eager to know how I could improve my code. Suggestions?</p>
