9.16. Chapter Assessment - List Methods

Check your understanding

Write code to add ‘horseback riding’ to the third position (i.e., right before volleyball) in the list sports.

Write code to take ‘London’ out of the list trav_dest.

Write code to add ‘Guadalajara’ to the end of the list trav_dest using a list method.

9.16.1. Chapter Assessment - Aliases and References

Check your understanding

9.16.2. Chapter Assessment - Split and Join

Write code to find the position of the string “Tony” in the list awards and save that information in the variable pos.

9.16.3. Chapter Assessment - For Loop Mechanics

Check your understanding

Currently there is a string called str1. Write code to create a list called chars which should contain the characters from str1. Each character in str1 should be its own element in the list chars.

9.16.4. Chapter Assessment - Accumulator Pattern

Check your understanding

For each character in the string saved in ael, append that character to a list that should be saved in a variable app.

For each string in wrds, add ‘ed’ to the end of the word (to make the word past tense). Save these past tense words to a list called past_wrds.

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list. (You should use the len function).

Create an empty string and assign it to the variable lett. Then using range, write code such that when your code is run, lett has 7 b’s ("bbbbbbb").

9.16.5. Chapter Assessment - Problem Solving

Below are a set of scores that students have received in the past semester. Write code to determine how many are 90 or above and assign that result to the value a_scores.

Write code that uses the string stored in org and creates an acronym which is assigned to the variable acro. Only the first letter of each word should be used, each letter in the acronym should be a capital letter, and there should be nothing to separate the letters of the acronym. Words that should not be included in the acronym are stored in the list stopwords. For example, if org was assigned the string “hello to world” then the resulting acronym should be “HW”.

Write code that uses the string stored in sent and creates an acronym which is assigned to the variable acro. The first two letters of each word should be used, each letter in the acronym should be a capital letter, and each element of the acronym should be separated by a “. ” (dot and space). Words that should not be included in the acronym are stored in the list stopwords. For example, if sent was assigned the string “height and ewok wonder” then the resulting acronym should be “HE. EW. WO”.

A palindrome is a phrase that, if reversed, would read the exact same. Write code that checks if p_phrase is a palindrome by reversing it and then checking if the reversed version is equal to the original. Assign the reversed version of p_phrase to the variable r_phrase so that we can check your work.

Provided is a list of data about a store’s inventory where each item in the list represents the name of an item, how much is in stock, and how much it costs. Print out each item in the list with the same formatting, using the .format method (not string concatenation). For example, the first print statment should read The store has 12 shoes, each for 29.99 USD.

You have attempted of activities on this page