computing with characters

C

cokofreedom

An obviously independent cause of uglyness is the inconsistency of eg
','.split() and ','.join()

Cheers, BB

I tend to do ", ".join("%s" % e for e in item)

Is there any difference between this and str()?
 
G

Gabriel Genellina

I tend to do ", ".join("%s" % e for e in item)

Is there any difference between this and str()?

Use the timeit module to measure performance:

C:\TEMP>python -m timeit "for i in xrange(10000): str(i)"
10 loops, best of 3: 81.8 msec per loop

C:\TEMP>python -m timeit "for i in xrange(10000): '%s' % i"
10 loops, best of 3: 78.5 msec per loop

The %s version consistently wins in my system -2.5.1 on WinXP- for a wide range of inputs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top