Contents
Write a function that contains assignment statements that do the following:
Define two lists (data1 and data2) which each have four numeric items. Then ...
Write a function that does the following:
Print each item from data1 on a separate line using a for statement.
Print each item from data1 and an index each on a separate line.
Print only the items for which the index is even (not odd) each on a separate line
Update each item in data2 by adding the corresponding item from data1. -- data2[i] = data1[i] + data2[i].
Using a list comprehension, create a new list from data1 in which each item is multiplied by 3. Print it.
Using a list comprehension, create a new list from the previous list in which only the even items (divisible by 2) are each multiplied by 2. Print it.
Given the following string (note the commas that separate fields and the white space around the commas):
data1 = "aaa bbb , ccc ddd , eee fff ggg"
Use list comprehension to create a list of fields that are separated by commas but with surrounding white space removed.
Using a for: statement with an else: clause, search a list for a value and if found, set a variable to that value, but if not found, set a variable to "not found".
Write a function that includes each of the following: