
Adventures in Python optimisation - robin_reala
https://www.robinwhittleton.com/2018/10/13/adventures-in-python-optimisation/
======
UncleEntity
Seems to me that it would be more efficient to modify BeautifulSoup's decoded
xml output rather than doing a bunch of string search/replacement/copying.

------
lixtra
Instead of going through each file len(note_range) times wouldn’t it be better
to search for noteref-[0-9]+ once and then bump the number on each found
occasion?

~~~
lixtra
Or more concrete do:

    
    
      s = """
      But I must explain to you how all this mistaken idea of denouncing pleasure and
      expound the actual teachings of the great explorer of the truth, the #endnote-1
      master-builder of human happiness. No one rejects, dislikes, or avoids pleasure
      #endnote-10 advantage from it? But who has any right to find fault with a man 
      that produces no resultant pleasure?  
      """
    
      import re
    
      def bump(match):
          return '#endnote-{}'.format(int(match.group(1))+1)
      r = re.sub(r'#endnote-(\d+)', bump, s)
      print(r)

