Which type should be used when testing static structure appartenance

Steven D'Aprano steve at pearwood.info
Wed Nov 18 08:30:36 EST 2015


On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote:

> On Wed, Nov 18, 2015 at 10:37 PM, Steven D'Aprano <steve at pearwood.info>
> wrote:
>> How about Python 3? Python 3 has the advantage of using set literals.
> 
> 2.7 has set literals too. 

Ah, so it does. I forgot about that. Most of my code has to run on multiple
versions (back to 2.4) and I remembered that set literals don't work:

[steve at ando ~]$ python2.6 -c "{1, 2, 3}"
  File "<string>", line 1
    {1, 2, 3}
      ^
SyntaxError: invalid syntax


> All the questions of performance should be 
> secondary to code clarity, though; 

"All"? Surely not.


> so I would say the choices are: Set 
> literal if available, else tuple. Forget the performance.

It seems rather strange to argue that we should ignore performance when the
whole reason for using sets in the first place is for performance.


-- 
Steven




More information about the Python-list mailing list