Movatterモバイル変換


[0]ホーム

URL:


string.join is abysmally slow

Darrellnews at dorb.com
Sun Apr 15 19:21:08 EDT 2001


### The name list is a built-in, avoid using such namesjoinList = []for line in buf.split("\012"):    # Comment or blank line?    if line == '' or line[0] in '#':        continue    else:        joinList.append(string.strip(line))##### Move the following out of the loop# "address1|address2|address3|addressN"regex = string.join(joinList,'|')regex = '"' + regex + '"'     #<-- Are you matching the quotes ?reo = re.compile(regex, re.I)################ Another approachimport re, stringbuf="""# xxxxre1re2#"""sep=")|("buf = re.sub("\012+",sep, re.sub("#.*", "",buf) )breakOff = len(sep)-1print buf[breakOff:-breakOff]"""output --> (re1)|(re2)"""--Darrell"Graham Guttocks" wrote:>> I've run into a performance problem in one of my functions, and wonder> if I could get some recommendations on how to speed things up.>


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp