进阶 对传入的数据进行分类
def bifurcate_by(lst, fn): print(lst) # [‘beep‘, ‘boop‘, ‘foo‘, ‘bar‘] print(fn(‘baby‘)) # True print(fn(‘abc‘)) # False print([ [x for x in lst if fn(x)], [x for x in lst if not fn(x)] ]) bifurcate_by( [‘beep‘, ‘boop‘, ‘foo‘, ‘bar‘], lambda x: x[0] == ‘b‘ ) # [[‘beep‘, ‘boop‘, ‘bar‘], [‘foo‘]]
相关推荐
kevinweijc 2020-08-18
ELEMENTS爱乐小超 2020-07-04
xiaoge00 2020-06-14
free0day 2020-05-25
cas的无名 2020-05-19
hongxiangping 2020-04-30
82550495 2020-02-20
风吹夏天 2020-02-17
80437916 2020-02-15
First00 2020-01-05
lert0 2019-11-19
wwater 2011-03-02
TianlangStudio 2019-11-03
wwater 2011-11-20
zhanggang 2019-09-26
dly 2015-05-29
Selier 2018-08-25
做你的老王 2015-08-19
KINGJENSEN 2010-10-09