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_final = ['Queen St. Cafe', 'Dumplings R Us']
    [[82, 'Queen St. Cafe'], [71, 'Dumplings R Us']]
    """
    list1=[]
    list2 = []
    
    for name in names_final:
        #making a list [%rating, restaurant name] for each restaurant in names_final.
        list1 = name_to_rating[name], name
        #making a list of lists withh all rating and names of restaurants in names_final. 
        list2.append(list1)
    #returning list of lists which are sorted by % rating of a restauarants.
    sorted_list = sorted(list2,key=lambda x: x[0],  reverse = True) 
    return sorted_list