I am trying to improve the performance of a script that takes lists and counts how many items are not in another "master" ( list_of_all_items) list .
It seems like there might be a more efficient way to do this, perhaps by combining the request in some way?
purple_count, brown_count, blue_count = 0, 0, 0
for item in list_of_purple_items:
if item not in list_of_all_items:
purple_count += 1
for item in list_of_brown_items:
if item not in list_of_all_items:
brown_list += 1
for item in list_of_blue_items:
if item not in list_of_all_items:
blue_count += 1
EDIT:
Thank you for your help. I checked a quick test to find out how best to use a large test case:
my original: 30.21s
sets: 00.02s
filter: 30.01s
sum generator: 31.08s
It's amazing how much more efficient to use sets.
Thanks again.
source
share