How do I get the "biggest" path?
Question: I need to write some Python code to get the latest version of Android from a
path. For example:

    
    
    $ ls -l android_tools/sdk/platforms/
    total 8
    drwxrwxr-x 5 deqing deqing 4096 Mar 21 11:42 android-18
    drwxrwxr-x 5 deqing deqing 4096 Mar 21 11:42 android-19
    $
    

In this case I'd like to have `android_tools/sdk/platforms/android-19`.


Answer: The [`max` function](https://docs.python.org/2.7/library/functions.html#max)
can take a `key=myfunc` parameter to specify a function that will return a
comparison value. So you could do something like:

    
    
    import os, re
    dirname = 'android_tools/sdk/platforms'
    files = os.listdir(my_dir)
    def mykeyfunc(fname):
        digits = re.search(r'\d+$', fname).group()
        return int(digits)
    print max(files, mykeyfunc)
    

Adjust that regular expression as needed for the actual files you're dealing
with, and that should get you started.

