Question: Write a program, in a file named count_items.py , which does the following: As with the population program, use input() to read a filename from


Write a program, in a file named count_items.py , which does the following: As with the population program, use input() to read a filename from the keyboard; open the file, and read its contents. (Use the prompt File to scan: for this input.) The input format is similar to the Population problem you just did; however, in this case, you can assume that the string will only have only one word (it will never have spaces in it). So make sure to remove leading and trailing whitespace, skip over comments, and ignore blank lines. But after you've handled all of this, each line will be string integer Your job will be to print out the totals, ordered first by the count, and (if there are duplicate counts), ordered by the word. EXAMPLE If your input looks like this: asdf 10 jkl 3 asdf -1 foobar 17 bbbb 17 then the last step of your output should be: jkl 3 asdf 9 bbbb 17 foobar 17 In summary, if the input to your program is: asdf 10 jkl 3 asdf -1 foobar 17 bbbb 17 then the output should look like this: STEP 1: THE ORIGINAL DICTIONARY Key: asdf Value: 9 Key: bbbb Value: 17 Key: foobar Value: 17 Key: jkl Value: 3 STEP 2: A LIST OF VALUE->KEY TUPLES [(9, 'asdf'), (17, 'bbbb'), (17, 'foobar'), (3, 'jkl')] STEP 3: AFTER SORTING [(3, 'jkl'), (9, 'asdf'), (17, 'bbbb'), (17, 'foobar')] STEP 4: THE ACTUAL OUTPUT jkl 3 asdf 9 bbbb 17 foobar 17
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
