1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

python3 mapとlambdaとは?

Last updated at Posted at 2021-09-07

mapとlambda

mapとはイテレータの要素を加工するためのもの

def triple(n):
  return n * 3

print(list(map(triple,[1, 2, 3])))

a = [10, 20, 30]

mapでリスト(イテレータ)を呼ぶとジェネレータになる。そのため結果をリストに変換する必要がある。

print(list(map(triple,a)))

###lambdaは上記の計算(triple)関数を書かなくても一行で実行できるものをいう。

print(list(map(lambda n: n*3, a)))
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?