jweinst1
6/7/2015 - 7:47 AM

## List Compressions with multi and sum.py

List Compressions with multi and sum.py

``````

def compress_list_multi(list): #multiplies the first half of a list by the indexes in the second half.
midpoint = (len(list) / 2)
one, two = list[0:midpoint], list[midpoint:len(list)]
return [one[i]*two[i] for i in range(len(one))]
def compress_list_sum(list):
midpoint = (len(list) / 2)
one, two = list[0:midpoint], list[midpoint:len(list)]
return [one[i]+two[i] for i in range(len(one))]
def compress_all_multi(list): #reduces a list to a single entry by multiplying all items.
while len(list) > 1:
midpoint = (len(list) / 2)
one, two = list[0:midpoint], list[midpoint:len(list)]
list = [one[i]*two[i] for i in range(len(one))]
return list
def compress_all_sum(list): #reduces a list to a single enty by adding all items.
while len(list) > 1:
midpoint = (len(list) / 2)
one, two = list[0:midpoint], list[midpoint:len(list)]
list = [one[i]+two[i] for i in range(len(one))]
return list

``````