nested looping

PK superprad at gmail.com
Wed Apr 8 17:15:58 EDT 2009


So I'm trying to see whats the cleanest way to do this:

I have a

checklist = [ax, bx, by, cy  ..] (a combination of a,b,c with x and y,
either both on one)

allist = [a,b,c,....]
xlist = [x, y, ..]

now I wanna loop through alist and xlist and see if the combination
exists in checklist

so something like,

for alpha in alist:
    for xy in xlist:
        if alpha+xy not in checklist:
            missing.append(alpha)

now the problem is I want to include alpha in missing list only if
none of the combinations from xlist with alpha are in checklist.

The above will exclude the possibility where ax doesn't exist but ay
or az does exist.

Hope There is a cleaner way to accomplish this.

Thanks in advance,
PK



More information about the Python-list mailing list