次の操作のうち、より高速なのはどれですか?
for ループの使用:
OrgIdChoices = []
Orgid_used_choices = [(choice["organization_id"])for choice in list(Organization.objects.all().values("organization_id"))] #Gets used ID's
OrgIdAvailChoices = [ "%c%c" % (x, y) for x in range(ord('A'), ord('Z')+1) for y in range(ord('A'), ord('Z')+1)] #Gets available ID's
for i in OrgIdAvailChoices:
if not i in Orgid_used_choices:
OrgIdChoices.append((i,i)) #Generates OrgIdAvailChoices which are not in Orgid_used_choices
または集合演算を使用:
OrgIdChoices = []
Orgid_used_choices = set([(choice["organization_id"])for choice in list(Organization.objects.all().values("organization_id"))])
OrgIdAvailChoices = set([ "%c%c" % (x, y) for x in range(ord('A'), ord('Z')+1) for y in range(ord('A'), ord('Z')+1)])
OrgChoices = OrgIdAvailChoices - Orgid_used_choices
for i in OrgChoices:
OrgIdChoices.append((i,i))