Author rhettinger
Recipients rhettinger
Date 2014-11-09.03:04:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1415502287.52.0.928876975666.issue22823@psf.upfronthosting.co.za>
In-reply-to
Content
There are many places where the old-style of creating a set from a list still persists.  The literal notation is idiomatic, cleaner looking, and faster.

Here's a typical change:


  diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
  --- a/Lib/sre_compile.py
  +++ b/Lib/sre_compile.py
  @@ -22,10 +22,10 @@
   else:
       MAXCODE = 0xFFFFFFFF
 
  -_LITERAL_CODES = set([LITERAL, NOT_LITERAL])
  -_REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT])
  -_SUCCESS_CODES = set([SUCCESS, FAILURE])
  -_ASSERT_CODES = set([ASSERT, ASSERT_NOT])
  +_LITERAL_CODES = {LITERAL, NOT_LITERAL}
  +_REPEATING_CODES = {REPEAT, MIN_REPEAT, MAX_REPEAT}
  +_SUCCESS_CODES = {SUCCESS, FAILURE}
  +_ASSERT_CODES = {ASSERT, ASSERT_NOT}

Here are typical timings:

  $ py34 -m timeit '{10, 20, 30}'
   10000000 loops, best of 3: 0.145 usec per loop

  $ py34 -m timeit 'set([10, 20, 30])'
  1000000 loops, best of 3: 0.477 usec per loop
History
Date User Action Args
2014-11-09 03:04:47rhettingersetrecipients: + rhettinger
2014-11-09 03:04:47rhettingersetmessageid: <1415502287.52.0.928876975666.issue22823@psf.upfronthosting.co.za>
2014-11-09 03:04:47rhettingerlinkissue22823 messages
2014-11-09 03:04:46rhettingercreate