#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb  3 10:55:48 2021

@author: pjoulaud
"""

def applique(f, l:list)->list :
    rep = []
    for elem in l :
        rep.append(f(elem))
    return rep

def reduit(f, depart, liste):
    for elem in liste :
        depart = f(depart, elem)
    return depart

#CORPS DE PROGRAMME
if __name__=='__main__':
    assert applique(len, ['Joe', 'Max-bill', 'Alexandra']) == [3, 8, 9]
    assert applique(lambda x:x**2, [2, 4, 5]) == [4, 16, 25]
    print(applique(lambda x:x.upper(), ['Joe', 'Max-bill', 'Alexandra']))
    mystere = lambda liste : applique(lambda nb:nb**2, liste)
    print(mystere([2,4,5])) #Ceci est equivalent de la fonction carré
    majuscule = lambda liste : applique(lambda x:x.upper(), liste)
    print(majuscule(['Joe', 'Max-bill', 'Alexandra']))

    assert reduit(lambda x,y:x+y, '', ['a', 'b', 'c', 'd'])=='abcd'
    tous_vrais = lambda liste : reduit(lambda x, y:x and y, True, liste)
    assert tous_vrais([3>2, len('Papa')==4, 4%2==0])==True
    taille = lambda liste : reduit(lambda x, y:x+1, 0, liste)
    print(taille([1,2,3,4,3,2,1]))
    filtre = lambda liste : reduit(lambda x, y:x+[y], [], liste)
    print(filtre(lambda x:x%2==0, [1,2,3,4,5,6]))
