Created
August 8, 2013 10:43
-
-
Save anonymous/6183623 to your computer and use it in GitHub Desktop.
Timeit's, split numbers into threes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: a = '12345678' | |
In [2]: %timeit [a[max(i-3,0):i] for i in range(len(a), 0, -3)][::-1] | |
100000 loops, best of 3: 2.19 us per loop | |
In [3]: %timeit format(int(a), ',').split(',') | |
100000 loops, best of 3: 2.04 us per loop | |
In [4]: %timeit [a[max(0,i-2+(len(a)-1)%3):i+1+(len(a)-1)%3] for i in range(0, len(a), 3)] | |
100000 loops, best of 3: 2.91 us per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment