Schreiben von Listenoperationen notieren
>>> a = ["a", "b", "c"]
>>> b = [1, 2, 3]
>>> dict(zip(a,b))
{'a': 1, 'c': 3, 'b': 2}
>>> #Lassen Sie nur 5 oder mehr Elemente
>>> a = [3, 6, 4, 7, 2, 10]
>>> filter(lambda x: x >= 5, a)
[6, 7, 10]
>>>
>>> #Gleich wie die Klammer unten
>>> fn = lambda x: x >= 5
>>> [i for i in a if fn(i)]
[6, 7, 10]
>>> #Addiere 5 zu allen Zahlen
>>> a = [3, 6, 4, 7, 2, 10]
>>> map(lambda x: x + 5, a)
[8, 11, 9, 12, 7, 15]
>>>
>>> #Gleich wie die Klammer unten
>>> fn = lambda x: x + 5
>>> [fn(i) for i in a]
[8, 11, 9, 12, 7, 15]
>>> #Füge alle Hinzu
>>> a = [3, 6, 4, 7, 2, 10]
>>> reduce(lambda x,y: x+y, a)
32
>>> #aufsteigende Reihenfolge
>>> a = [3, 6, 4, 7, 2, 10]
>>> sorted(a)
[2, 3, 4, 6, 7, 10]
Recommended Posts