1
skyleft Sep 24, 2012 y=lambda listA:bool([x for x in listA if x['ID']==14])
|
2
reus Sep 24, 2012
any(map(lambda d: d.get('ID', None) == 14, l))
|
3
013231 Sep 24, 2012 any(item['id'] == 14 for item in listA)
|
4
reus Sep 24, 2012 这个比刚才的更快,因为是generator,遇到为True的就直接返回了,不用遍历整个list
any(d for d in l if d.get('ID', None) == 14) 比如l = [{'ID': 14}] * 5000000,用这个会秒回,map的话慢很多= = |
7
013231 Sep 24, 2012
|
9
Veelian Sep 24, 2012
你确定list里是字典?
|