Question: Create a new function that will return a variable named rankings, which is a list of dictionaries set up as follows: rankings [ i ]

Create a new function that will return a variable named rankings, which is a list of dictionaries set up as follows:
rankings [i] is a dictionary corresponding to the restaurant whose rank is i+1. For example, from the screenshot above, rankings [0] should be a
dictionary with information about Gus's World Famous Fried Chicken.
Each dictionary, rankings [i], should have these keys:
rankings [i]['name ']: The name of the restaurant, a string.
rankings[i]['stars']: The star rating, as a string, e.g.,'4.5','4.0'
rankings [i]['numrevs']: The number of reviews, as an integer.
rankings [i]['price ']: The price range, as dollar signs, e.g.,'$','$$','$$$', or '$$$$'.
Of course, since the current topic is regular expressions, you might try to apply them (possibly combined with other string manipulation methods) find the
particular patterns that yield the desired information.
In [4]:
### Define demo inputs
demo_str_ex0= yelp_html
The demo included in the solution cell below should display the following output:
extract_ranking(demo_str_ex0)->
[{'name': 'Gus's World Famous Fried Chicken',
'stars': '4.0',
'numrevs': 549,
'price': '$$'},
{'name': 'South City Kitchen - Midtown',
'stars': '4.5',
'numrevs': 1777,
'price': '$$'},
{'name': 'Mary Mac's Tea Room',
'stars': '4.0',
'numrevs': 2241,
'price': '$$'},
{'name': 'Busy Bee Cafe', 'stars': '4.0', 'numrevs': 481, 'price': '$$'},
{'name': 'Richards' Southern Fried',
'stars': '4.0',
'numrevs': 108,
'price': '$$'},
{'name': 'Greens & Gravy', 'stars': '3.5', 'numrevs': 93, 'price': '$$'},
{'name': 'Colonnade Restaurant',
'stars': '4.0',
'numrevs': 350,
'price': '$$'},
{'name': 'South City Kitchen Buckhead',
'stars': '4.5',
'numrevs': 248,
'price': '$$'},
{'name': 'Poor Calvin's', 'stars': '4.5', 'numrevs': 1558, 'price': '$$'},
{'name': 'Rock's Chicken & Fries',
'stars': '4.0',
'numrevs': 67,
'price': '$'}]
Create a new function that will return a variable

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!