Gary Wilson Jr wrote:
> Gary Wilson Jr wrote:
>
>>alpha = 'abcdefghijklmnopqrstuvwxyz'.upper()
>>pairs = [x for x in alpha] + [''.join((x,y)) for x in alpha for y in alpha]
>
> I forget, is string concatenation with '+' just as fast as join()
> now (because that would look even nicer)?
Certain looping constructs like:
x = ''
for y in z:
x += y
are now (in CPython 2.4) somewhere near the speed of:
x = []
for y in z:
x.append(y)
x = ''.join(x)
but this isn't really relevant to your problem because you're only
joining two characters:
$ python -m timeit -s "import string; a = string.ascii_uppercase"
"[''.join([x, y]) for x in a for y in a]"
1000 loops, best of 3: 1.02 msec per loop
$ python -m timeit -s "import string; a = string.ascii_uppercase"
"[x + y for x in a for y in a]"
1000 loops, best of 3: 295 usec per loop
Unsurprisingly, it's actually faster to simply concatenate the two
characters.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list