Complete the tasks below. Please turn in a single Jupyter notebook named 4_first_last.ipynb (substitute your first and last name). Please run Kernel > Restart & Run All on your notebook before turning in.
- Create a list of 10 random integers in the range of -100 to 100.
- Loop through that list using a for loop. Put the non-negative (positive or zero) integers into a new list. If negative integers are encountered, print a message saying that the value is negative and printing that value.
- Write a function that does what you did in part A but with the following differences:
- The input list can be any list of numbers.
- The function should take as a parameter a threshold for being included in the new list (e.g., if you want non-negative integers, the threshold would be 0, and the function would check if values are >= to this value).
- The printed message for failing to be included should also report the threshold parameter.
- The new list should be returned by the function.
- Execute the function on your list of 10 random integers.
- Create a two-dimensional list with 3 'rows' and 4 'columns' and a mixture of strings and integers.
- Loop through each element of the list and check if each element is a string or an integer. Save the strings as a dictionary with the index (row, column) as the key and the string as the value. Save the integers as a dictionary with the index (row, column) as the key and the integer as the value.
- Print out your dictionaries (no
printcommand required).
- Create a list of 5 strings that are first and last names, e.g.
'Jon Doe'. - Use a list comprehension (a single-line command) to get the first initial from each name and store each string (e.g.
'J') in a new list. Print this list (noprintcommand required). - Repeat but store both the first and last initial (e.g.
'JD') in a new list. Print this list (noprintcommand required). - Save this second list to a text file.
- Download this text file of past World Series winners.
- Read in the lines of the file to a list, so that each line is an element of the list.
- Create a new list with just those list elements that contain 'New York'; print that list, making sure there's not an extra newline character between each line. Print this list (no
printcommand required). - Use the
setclass to convert the list of all World Series winners to a list of unique values. Print this list (noprintcommand required). - Write the output to a new file.