Is regex the best approach for this?
Question: Im looking to match an item from a list and place that item into a variable.
Below is what I have put together so far, but currently Im not sure how to
create the regex I need to match just the 1 item and I am not sure if this is
the best approach. I am trying to match the item in the list with '/site-
packages' on the end.

**Test Data** (output from sites)

    
    
    ['/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/site-python', '/Library/Python/2.7/site-packages']
    

**Code**

    
    
    import site
    import re
    sites = site.getsitepackages()
    print sites
    site = re.compile('*/site-packages')
    
    for item in sites:
        m = site.search(item)
        if m:
            print m
    


Answer: In this case you could also use the string `in` operator in a list
comprehension

    
    
    m = [i for i in sites if r'/site-packages' in i]
    

Similarly you could use `endswith`

    
    
    m = [i for i in sites if i.endswith(r'/site-packages')]
    

**Edit**  
To get the smallest element (by length) once the list comprehension has
executed you can do

    
    
    min(m, key=len)
    

