Replace every n instances of a string

Simon Bayling sfb at alysseum.com
Fri Aug 15 18:50:53 EDT 2003


> Any ideas?  Do I not want to search for "\\u" but instead just insert
> a \n after each 72 characters (equivalent to 12 \uXXXX codes)? 

If you really mean "after each 72 characters", then something like this;

output = []
for i in len(0, s, 72):
    	output.append(s[i:i+72] + '\n')

print ''.join(output)


> Would this provide better performance?  
Would what provide better performance than what in what scenario(s)?

The difference between the original string and the string with newlines is 
probably insignificant...

- Simon.




More information about the Python-list mailing list