compare list

Ben Bush pythonnew at gmail.com
Tue Nov 15 00:56:23 EST 2005


>
> [snip]
>
> That's potentially very expensive for large lists, although simply
> converting the lists to sets should give a significant speed up. I
> think the following is *possibly* as good a way as any.
>
> >>> def compare(list1, list2):
> intersection = sorted(list(set(list1) & set(list2)))
> for i in range(len(intersection) - 1):
> if intersection[i] == intersection[i+1] - 1:
> return True
> return False
>
> Duncan

 Why it is potentially very expensive for large lists? what does
intersection mean in Duncan's code? Thanks a lot for your patience!

> --
> Thanks!
> Ben Bush
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051114/9c3b3b38/attachment.html>


More information about the Python-list mailing list