Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Oeps! Apologies for any inconvenience caused.

I typed the examples above.... not a good idea. Still the point raised is valid.

def test1():
    for k in xmrange([10]*3): k
    return

def test2():

    for k1 in xrange(10):
        for k2 in xrange(10):
            for k3 in xrange(10): [k1,k2,k3]
    return

timeit('test1()')

timeit('test2()')

625 loops, best of 3: 1.22 ms per loop

625 loops, best of 3: 256 µs per loop