【python – 列出搜索优化】教程文章相关的互联网学习教程文章

python – 列出搜索优化【代码】

first = [(1, text, text, 1, 2, 3), (1, text, text, 1, 0, 3), ... (6054, text, text, 2, 2, 3)] second = (1, 2, 3, 4, 5 ... 5412)有没有更快的方法来做到这一点:data = [x for x in first if x[0] in second]解决方法:试试这个:first = [(1, text, text, 1, 2, 3), (1, text, text, 1, 0, 3), ... (1054, text, text, 2, 2, 3)] second = (1, 2, 3, 4, 5 ... 5412) second_set = set(second) data = [x for x in first if ...