python 列表推导式

可以看到使用列表推导式可以得到2倍速的提高

ex0

##self.CLASSES ('car', 'truck', 'trailer', 'bus', 'construction_vehicle', 'bicycle', 'motorcycle', 'pedestrian', 'traffic_cone', 'barrier')

self.cat2id = {name: i for i, name in enumerate(self.CLASSES)}

ex1

mountains = [
    ['Makalu', 8485],
    ['Lhotse', 8516],
    ['Kanchendzonga', 8586],
    ['K2', 8611],
    ['Everest', 8848]
]

highest_mountains = [m for m in mountains if m[1] > 8600]
posted @ 2024-01-17 17:51  无左无右  阅读(1)  评论(0编辑  收藏  举报