Em Sex, 2006-04-14 às 12:46 +1000, Steven D'Aprano escreveu: > Why would you want to call in the heavy sledgehammer of regular > expressions for cracking this peanut?
And put heavy on that! $ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6 4 0'" 'str.replace(" ", "")' 100000 loops, best of 3: 3.07 usec per loop $ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6 4 0'" '"".join(str.split())' 100000 loops, best of 3: 4.16 usec per loop $ python2.4 -mtimeit -s "from re import sub; str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6 4 0'" 'sub("\\s", "", str)' 10000 loops, best of 3: 23.6 usec per loop $ calc 23.6 / 3.07 ~7.68729641693811074919 I couldn't be expressed better: "Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski, in comp.lang.emacs -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list