Is it pythonic: naming lambdas

后端 未结 3 485
我寻月下人不归
我寻月下人不归 2020-11-27 08:18

I\'m beginning to appreciate the value of lambda expressions in python, particularly when it comes to functional programming, map, functions returning functions

3条回答
  •  情歌与酒
    2020-11-27 08:46

    These are functionally (no pun intended) identical.

    indexer = lambda a0, a1, idx: a0[idx] + a1[idx]
    
    def indexer(a0, a1, idx):
        return a0[idx] + a1[idx]
    

    If you have an aesthetic preference for one or the other, then use it.

提交回复
热议问题