Update apt.py: Python golf!

Untested, should work down to python 2.7 though. Python versions prior to 2.7 do not have dict comprehension.

These changes should reduce overhead by only doing re.match/str.find once instead of twice.

Depending on the amount of matching this needs to do, it might be worth considering [re2](https://code.google.com/p/re2/) instead of python's default re.