note écriture de l'opération de liste
>>> a = ["a", "b", "c"]
>>> b = [1, 2, 3]
>>> dict(zip(a,b))
{'a': 1, 'c': 3, 'b': 2}
>>> #Ne laissez que 5 éléments ou plus
>>> a = [3, 6, 4, 7, 2, 10]
>>> filter(lambda x: x >= 5, a)
[6, 7, 10]
>>>
>>> #Identique au support ci-dessous
>>> fn = lambda x: x >= 5
>>> [i for i in a if fn(i)]
[6, 7, 10]
>>> #Ajouter 5 à tous les nombres
>>> a = [3, 6, 4, 7, 2, 10]
>>> map(lambda x: x + 5, a)
[8, 11, 9, 12, 7, 15]
>>>
>>> #Identique au support ci-dessous
>>> fn = lambda x: x + 5
>>> [fn(i) for i in a]
[8, 11, 9, 12, 7, 15]
>>> #Tout ajouter
>>> a = [3, 6, 4, 7, 2, 10]
>>> reduce(lambda x,y: x+y, a)
32
>>> #ordre croissant
>>> a = [3, 6, 4, 7, 2, 10]
>>> sorted(a)
[2, 3, 4, 6, 7, 10]
Recommended Posts