from operator import itemgetter


def build_rating_list(name_to_rating, names_final):
    """ (dict of {str: int}, list of str) -> list of list of [int, str]

    Return a list of [rating%, restaurant name], sorted by rating%

    >>> name_to_rating = {'Georgie Porgie': 87,
     'Queen St. Cafe': 82,
     'Dumplings R Us': 71,
     'Mexican Grill': 85,
     'Deep Fried Everything': 52}
    >>> names = ['Queen St. Cafe', 'Dumplings R Us']
    [[82, 'Queen St. Cafe'], [71, 'Dumplings R Us']]
    """  
    final = []
    if len(names_final) == 1:
        return [int(name_to_rating.get(names_final[0])[:-1]), "".join(names_final)]
    for restaurant_name in names_final:
        if restaurant_name in name_to_rating:
            final.append([int(name_to_rating.get(restaurant_name)[:-1]), restaurant_name])
    final.sort(key=itemgetter(0), reverse=True)
    return final