Question

In a python program, create an empty dictionary. Your program must search the attached lyric text...

In a python program, create an empty dictionary. Your program must search the attached lyric text (Sweet Child O' Mine Lyrics.docx) for the string 'child'. Upper and lower case counts. Each time that you find the string 'child' find the word that follows and add the tuple (the line number of that line and the word that follows) to your dictionary.  Print out the dictionary to a file.

(Sweet Child O' Mine Lyrics.docx) Contents below

She's got a smile that it seems to me
Reminds me of childhood memories
Where everything was as fresh as the bright blue sky
Now and then when I see her face
She takes me away to that special place
And if I stare too long, I'd probably break down and cry

Whoa, oh, oh
Sweet child o' mine
Whoa, oh, oh, oh
Sweet love of mine

She's got eyes of the bluest skies
As if they thought of rain
I'd hate to look into those eyes and see an ounce of pain
Her hair reminds me of a warm safe place
Where as a child I'd hide
And pray for the thunder and the rain to quietly pass me by

Whoa, oh, oh
Sweet child o' mine
Whoa whoa, oh, oh, oh
Sweet love of mine

Whoa, yeah
Whoa, oh, oh, oh
Sweet child o' mine
Whoa, oh, whoa, oh
Sweet love of mine
Whoa, oh, oh, oh
Sweet child o' mine
Ooh, yeah
Ooh, sweet love of mine

Where do we go?
Where do we go now?
Where do we go?
Ooh, oh, where do we go?
Where do we go now?
Oh, where do we go now?
Where do we go? (Sweet child)
Where do we go now?
Ay, ay, ay, ay, ay, ay, ay, ay
Where do we go now?
Ah-ah

Where do we go?
Oh, where do we go now?
Oh, where do we go?
Oh, where do we go now?
Where do we go?
Oh, where do we go now?
Now, now, now, now, now, now, now
Sweet child
Sweet child of mine

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#opening the file
file = open("lyrics.docx")
#reading the lines
lines = [x.split('\n')[0].split(' ') for x in file.readlines()]

#dictionary
lyrics = {}
#calculating the number of 'child'
num = 0

for lineNum,i in enumerate(lines):
for n,j in enumerate(i):
#if a word in a line contains child and is not childhood
if('child' in j and j != 'childhood'):
#if 'child' is the last word in the line
if(n == (len(i)-1)):
#the first word of the next line is added to the tuple
lyrics[num] = (lines[lineNum + 1][0], (lineNum+2))
else:
#otherwise the next word in the same line gets added to the tuple
lyrics[num] = (lines[lineNum][n+1], (lineNum+1))
num += 1
#opening the output file
out = open('output.txt','w+')
for i in range(num):
#writing the dicitonary to the output file
out.writelines(str(lyrics.get(i))+"\n")
#closing the files
out.close()
file.close()
print('Done!')

________________________________________

CODE IMAGES:

In [14]: 4 7 num = 0 1 #opening the file 2 file = open(lyrics.docx) 3 #reading the lines lines = [x.split(\n)[0].split(

lyrics.docx(the blank lines are also counted while calculating the line number you can remove the blank lines if you want)

- lyrics.docx - Notepad File Edit Format View Help Shes got a smile that it seems to me Reminds me of childhood memories Whe

output.txt

output.txt - Notepad Х File Edit Format View Help (o, 9) (Id, 17) (o, 21) (o, 27) (o, 31) (Where, 42) (Swee_____________________________________________

Feel free to ask any questions in the comments section
Thank You!

?mid=&wid=52562&sid=&tid=8561&rid=LOADED?mid=&wid=52562&sid=&tid=8561&rid=BEFORE?mid=&wid=52562&sid=&tid=8561&rid=FINISH?mid=&wid=52562&sid=&tid=8561&rid=OPTOUT

Add a comment
Know the answer?
Add Answer to:
In a python program, create an empty dictionary. Your program must search the attached lyric text...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Writ 3 paragraphs on the following paragraph by answering this question: Compare the communication skills shown...

    Writ 3 paragraphs on the following paragraph by answering this question: Compare the communication skills shown by the narrator and the old man, e.g., balancing strong feelings, rationality, assertiveness, relationships, and listening. Article: THE TRAIN CLANKED and rattled through the suburbs of Tokyo on a drowsy spring afternoon. Our car was comparatively empty - a few housewives with their kids, some old folks going shopping. I gazed absently at the drab houses and dusty hedgerows. At one station the doors...

  • While reading the story, consider the culture (or sub culture) and related communication styles the story...

    While reading the story, consider the culture (or sub culture) and related communication styles the story reveals. Consider too, possibly, the values, behavioral norms, social practices, social artifacts, etc. After reading the story through the lens of this idea, please compose a full academic length (evidence-based 7 to 11 sentence long) paragraph which addresses the following prompt: What does the story reveal about the culture it portrays and/OR the communication styles the culture shares? In other words, what does the...

  • Write 6-7 Sentences For Your Response: Did the City of Dixon have the appropriate internal controls?...

    Write 6-7 Sentences For Your Response: Did the City of Dixon have the appropriate internal controls? What elements do you think they fell short in? Information Welcome to Dixon Illinois about an hour and a half west of bustling Chicago but it has the genteel feel of a small town from the Dixon arch, a lucky horseshoe that hangs over the quaint community to the bright white boyhood home of Ronald Reagan. Reagan isn't just Dixon's claim to fame, he's...

  • Overview Title Manager's Hot Seat: Listening Skills: Yeah, Whatever Pilar Grimault has scheduled a meeting with...

    Overview Title Manager's Hot Seat: Listening Skills: Yeah, Whatever Pilar Grimault has scheduled a meeting with her department’s young Creative Director, Miguel Valentino. He has recently completed a campaign for a longstanding client, Jezebel. Although the campaign was a huge success, the client has complained to Pilar about Miguel’s project management skills. Here's the video transcript -Hello. Hey, I just came down the street, and I was stopped by three different people. We're a hit. We're a huge hit. i...

  • Response Questions Part A To C A) Did the City of Dixon have the appropriate internal...

    Response Questions Part A To C A) Did the City of Dixon have the appropriate internal controls? What elements do you think they fell short in? B) Who should have detected the fraud first? and why? C) Please share your thoughts about information below and what surprised you most about the information below? Information Welcome to Dixon Illinois about an hour and a half west of bustling Chicago but it has the genteel feel of a small town from the...

  • Shady Slim / Comprehensive Deductions Problem Read the following letter and help Shady Slim with his...

    Shady Slim / Comprehensive Deductions Problem Read the following letter and help Shady Slim with his tax situation. Assume that gross income is $172,900 (which consists only of salary) and ignore AGI thresholds for purposes of this problem. December 31, 2020 To the friendly student tax preparer: Hi, it’s Shady Slim again. I just got back from my 55th birthday party, and I’m told that you need some more information from me in order to complete my tax return. I’m...

  • 52. Read the following letter and help Shady Slim with his tax situation. Please assume that...

    52. Read the following letter and help Shady Slim with his tax situation. Please assume that his gross income is $172,900 (which consists only of salary) for purposes of this problem. December 31, 2019 To the friendly student tax preparer: Hi, it's Shady Slim again. I just got back from my 55th birthday party, and I'm told that you need some more information from me in order to complete my tax return. I'm an open book! I'll tell you whatever...

  • Read the case and Summarizes the situation as you see it. Describes what Organizational Development is and its core valu...

    Read the case and Summarizes the situation as you see it. Describes what Organizational Development is and its core values Good morning. Northern County Legal Services," Christina said. "How can I help you? Yes, I see. Okay, why don't I schedule a time for you to stop by and talk with one of us about your situation and we can see how we can help? I'm free on the 12th at 3:30 p.m. Does that work for you? Excellent. And...

  • Choose a symbol from either "The Gift of the Magi" and discuss what significance this symbol...

    Choose a symbol from either "The Gift of the Magi" and discuss what significance this symbol had to you as the reader (an example of this would be the combs Jim gave to Della and a discussion about a precious gift that you received or gave). Use text examples in this section. If someone were to write your life story, what symbol would be present and why?  How does this symbol represent you?   You can attach a picture of your symbol (an...

  • essay about the wonderful lousy poem UD SOLO The Wonderful Lousy Poem Abroad - abie. 77...

    essay about the wonderful lousy poem UD SOLO The Wonderful Lousy Poem Abroad - abie. 77 hen I was egter nie year y ou Arte y father was father was a Hollywood only head of thermount Studios. My mother was a for d e move in various intellectual projects, help teng e to the exuberant Hollywood.com My mother read the little poem and began to cry Buddy you didn't really write this beautiful beautiful poem Shyly proud bunting stammered that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT