Thank you. I figured the set would probably be faster, but the lists are small, and I'm concerned that the code is going to look Byzantine if I keep swapping between lists, sets and dictionaries :~).
At the moment there are no sets or dictionaries in the entire code base I am working with. I'm not sure if the place I am looking at right now is supposed to support duplicates or not: duplicates are permitted, but they cause report anomalies. Steve. "Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "bambam" <[EMAIL PROTECTED]> writes: >> Is it safe to write >> A = [x for x in A if x in U] >> or is that undefined? I understand that the slice operation >> can be used to make a temporary copy, so I could write >> A=[x for x in A[:] if x in U] >> but I've just copied that without any understanding. > > You get a temporary copy either way; note you're going to linearly > search U on every pass. Maybe you want: > > SU = set(u) > A = [a for x in A if x in SU] > > or possibly > > A = list(set(A) & set(U)) > > which will remove duplicate elements from A and not necessarily keep > them in the same order, but is likely to be fastest of the bunch. -- http://mail.python.org/mailman/listinfo/python-list