# map filter zip reduce
# map()
my_list = [1,2,3]
def multiply_by_two(item):
return item*2
print(list(map(multiply_by_two, my_list)))
print(my_list)
# map here iteratw through databand create a
#new list, the data will remain unchanged
# filter()
def only_odd(item):
return item % 2 != 0
print(list(filter(only_odd, my_list)))
# zip()
your_list = [5,6,7]
print(list(zip(my_list, your_list)))
# reduce()
from functools import reduce
def accumulator(acc, item):
return acc + item
print(reduce(accumulator, my_list, 0))
#params are function, data , initial acc
#EXCERCISE
from functools import reduce
#1 Capitalize all of the pet names and print the list
my_pets = ['sisi', 'bibi', 'titi', 'carla']
def capitalize(string):
return string.upper()
print(list(map(capitalize, my_pets)))
#2 Zip the 2 lists into a list of tuples, but sort the numbers from lowest to highest.
my_strings = ['a', 'b', 'c', 'd', 'e']
my_numbers = [5,4,3,2,1]
print(list(zip(my_strings, my_numbers)))
#3 Filter the scores that pass over 50%
scores = [73, 20, 65, 19, 76, 100, 88]
def is_passed(score):
return score > 50
print(list(filter(is_passed, scores)))
#4 Combine all of the numbers that are in a list on this file using reduce (my_numbers and scores). What is the total?