Retourner au contenu associé (journal : Lisp: pourquoi est-ce different ?)
Posté par 태 (site web personnel) le 16 avril 2005 à 12:09. En réponse au journal Lisp: pourquoi est-ce different ?. Évalué à 5.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
[^] # Re: un environnement
Posté par 태 (site web personnel) . En réponse au journal Lisp: pourquoi est-ce different ?. Évalué à 5.
>>> square=lambda x:x*x
>>> ma_liste=[1,2,3,4,5]
>>> [square(x) for x in ma_liste]
[1, 4, 9, 16, 25]
Le find_all :
>>> [x for x in [1, 3, 12, 4] if x >2 and x < 6]
[3, 4]
Mais on peut aussi écrire map, ou filter (pour find_all).
>>> map(square, ma_liste)
[1, 4, 9, 16, 25]
>>> filter(lambda x: x>2 and x<6, [1, 3, 12, 4])
[3, 4]