Question: knew Sweeter dewan Q1 That Magic Moment The string tmm, below, contains the lyrics to Lou Reed's this magic moment. Notice that we can can

knew Sweeter dewan Q1 That Magic Moment The string tmm, below, contains the lyrics to Lou Reed's this magic moment. Notice that we can can enclose line breaks in a string by using triple quotes as delimiters. In [7]: tmm = "' 'This magic moment so different, and so new Was like any other Until I met you And then it happened You took me by surprise I that you felt it too I could see it by the look in your eyes wine Softer than a summer's night Everything I want, I have Whenever I hold you tight This magic moment While your lips are close to mine Will last forever Forever, 'til the end of time So why won't you dance with me Hey babe Why won't you dance with me This magic moment So different, and so new Was like any other Until I met you And then it happened You took me by surprise I knew that you felt it too I could see it by the look in your eyes Sweeter than wine weete Softer than a summer's night Everything I want, I have Whenever I hold you tight This magic moment Sweeter than wine Softer than a summer's night So please, baby So please Save the last dance for me!!! In the next cell, write a small program that will print the number of words in the song. There are many different ways to accomplish this, but here is one that might be easy and interesting: recall that we can create a list of substrings of a string, delimited by a particular character by calling the string.split('char') function. Note however, that in tmm there are two types of characters that separate words: spaces and line breaks. The character encoding for line breaks is . So, first should replace all the line breaks with spaces (use string.replace('old', 'new') function), then split on spaces, then count the length of the resulting list. localhost:8888bconvert/html/Downloads/PS1 (1).ipynb?download=false 1/5 26/01/2021 PS1 (1) Things to watch out for: In needs to be surrounded by quotes to read as a string strings are immutable, meaning that functions on them do not change the string, but rather create a new string. Specifically, the string.split method creates a new string, so make sure you are working with this new string. In ]: Now, lets count how many times Lou Reed says "i" in the song. This is very easy using the .count method, but don't. Instead, use a for loop to count the instances of "T", check that you did this correctly using the .count method. **Hint:** Create a counter helper variable that gets (potentially) changed within each loop. You will also need to use conditional statements. In ): Okay, lets up things a notch. Count how many i 's (the letter, not the word) there are in all the words of the song. Count both upper and lower case i 's. This can be done by manually counting both upper and lower case, or by making a whole string lowercase with the string. lower() method. **Hint:** Recall that strings act a lot like lists; for instance, you can call the string.count('char') method to count the instances of char in string . In )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
