Restaurant sorting. The text file scores.txt contains a series of local restaurant ratings. Each line looks like this:
Restaurant Name: Rating
I'm trying to write a program that reads the file and then spits out the ratings In alphabetical order by restaurant.
These are the contents of the scores.rtf file:
Pancho Villa:3
Andalu:3
Urbun Burger:1
El Toro:5
Casa Thai:2
Taqueria Cancun:2
Little Baobab:1
Charanga:3
Irma's Pampanga:5
Bay Blend Coffee and Tea:3
Giordano Bros:2
Two Amy's: 5
Chef Geoff: 3
I'm not sure where to start with this.
Let's think through this. You have an input with a regular format: a name and a value, separated by a colon :
. You'll need to open the file and read each line, then split the line into two parts, name and value. Think about what kind of data structure would be best for holding these values. Once you've read through the file and closed it, you just need to sort your data structure alphabetically, and print out the contents. Easy enough?