Bug/Feature/Undocumted bonus? I was surprised not to get a syntax error in `assert {'1','2'}.intersection('12') `

I’ve been using Python since 1.4 and was somewhat surprised to see this typo working:

assert {'1','2'}.intersection('12')

I would have expected it to give me a syntax error, claiming that this is required:

assert {'1','2'}.intersection(set('12'))

Is it just me who can’t read the documentation :blush: ?
Is this a hidden feature or a bug?
I’m not quite sure…?

/B

Note, the non-operator versions of union() , intersection() , difference() , and symmetric_difference() , issubset() , and issuperset() methods will accept any iterable as an argument. In contrast, their operator based counterparts require their arguments to be sets. This precludes error-prone constructions like set('abc') & 'cbs' in favor of the more readable set('abc').intersection('cbs') .

Thanks @benjamin - I didn’t know,

I think it would be good to add your reply to the documentation.

Kind regards
Bjorn

Look about 15 lines down from the link you originally posted :slight_smile:

:blush:. It must have been one of those days :rofl: