# 23.6. Exercises¶

1. Write equivalent code using map instead of the manual accumulation below and assign it to the variable test.

1. Use manual accumulation to define the lengths function below.

1. Now define lengths using map instead.

1. Now define lengths using a list comprehension instead.

1. Write a function called positives_Acc that receives list of numbers as the input (like [3, -1, 5, 7]) and returns a list of only the positive numbers, [3, 5, 7], via manual accumulation.

1. Write a function called positives_Fil that receives list of things as the input and returns a list of only the positive things, [3, 5, 7], using the filter function.

1. Write a function called positives_Li_Com that receives list of things as the input and returns a list of only the positive things, [3, 5, 7], using the list comprehension.

1. Define longwords using manual accumulation.

1. Define longwords using filter.

1. Define longwords using a list comprehension.

1. Write a function called longlengths that returns the lengths of those strings that have at least 4 characters. Try it with a list comprehension.

1. Write a function called longlengths that returns the lengths of those strings that have at least 4 characters. Try it using map and filter.

1. Write a function that takes a list of numbers and returns the sum of the squares of all the numbers. Try it using an accumulator pattern.

1. Write a function that takes a list of numbers and returns the sum of the squares of all the numbers. Try it using map and sum.

1. Use the zip function to take the lists below and turn them into a list of tuples, with all the first items in the first tuple, etc.

1. Use zip and map or a list comprehension to make a list consisting the maximum value for each position. For L1, L2, and L3, you would end up with a list [4, 5, 3, 5].

1. Write code to assign to the variable compri_sample all the values of the key name in the dictionary tester if they are Juniors. Do this using list comprehension.

1. Challenge The nested for loop given takes in a list of lists and combines the elements into a single list. Do the same thing using a list comprehension for the list L. Assign it to the variable result2.

1. Challenge: Write code to assign to the variable class_sched all the values of the key important classes. Do this using list comprehension.

1. Challenge: Below, we have provided a list of lists that contain numbers. Using list comprehension, create a new list threes that contains all the numbers from the original list that are divisible by 3. This can be accomplished in one line of code.