Joined June 2012
·

Doug Thomas

Senior Software Engineer at PokitDok, Inc.
·
Charleston, SC
·
·
·

Posted to Use the in operator over 1 year ago

I guess this answers my question (thanks @corbinbs):

http://stackoverflow.com/questions/3340539/why-tuple-is-faster-than-list/3340881#3340881

I'll make a final tweak to use a tuple. :)

Posted to Use the in operator over 1 year ago

I just fixed some older code that I had written that did this. Perhaps I had added the second check later, but at any rate I refactored it yesterday. I used a list, however, as opposed to a tuple:

if value in ['cheese', 'bacon']:

I would say for values like this the performance is essentially the same, but is there a reason to favor one over the other?

Sweet! I'll definitely check this out.

Achievements
103 Karma
16,109 Total ProTip Views