Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

I thought it seemed odd that Python supported the AND operator on lists, but it doesn't.

You do need to convert to a set first, e.g.

  [1,2,3] & [1,2]
gives a TypeError, while

  set([1,2,3]) & set([1,2])
gives set([1,2]) as expected.


view as:

You can also write sets in a more compact notation in python as:

    {1,2,3} & {1,2}
Which gives {1,2} as a result.

Thank you for catching this! I did in fact call set on the comments outside of that function. I've updated the blog post.

Legal | privacy