Honors 1000, Productive Data Manipulation in Python and SQL (Fall 2020)

Homework 2 (Due: October 12, Monday)

Handin under assignment 2 (sudo handin1000 2 SongLyrics.py)

SONG LYRICS

In this problem you will read a text file containing the lyrics of a song (assume no blank lines in the lyrics) and store each word that appears in the song in a Python Dictionary whose key is the word and the value is a list of positions where the word appears in the lyric (starting at 1). If the word appears at the end of a line, you should store the negative of the position to indicate end of line. Then, using the dictionary you will produce the following output:
  • display the map
  • display the lyrics
  • Total number of unique words in the song
  • Most frequent word (if there is a tie, display any one of them)
Here is a sample file, song1.txt:
What have I
What have I
What have I done to deserve this
and here is a sample run of the program:
macbook-pro:f20 raj$ python3 SongLyrics.py song1.txt 

Map:

WHAT            [1, 4, 7]
HAVE            [2, 5, 8]
I               [-3, -6, 9]
DONE            [10]
TO              [11]
DESERVE         [12]
THIS            [-13]

Song:

WHAT HAVE I
WHAT HAVE I
WHAT HAVE I DONE TO DESERVE THIS

The number of unique words in the lyric is:  7

Most frequent word:  WHAT 

Some sample Song Lyrics files:

song1.txt

song2.txt