A long long time ago, I started with Python 1.5 at web.de, founded the MoinMoin wiki project shortly thereafter, and am now enjoying the increased traction that Python recently gets from data science.
Python – No doc strings etc., it's a challenge after all…
importredefclean_text(text,_back_hash=re.compile(r'[^#]#')):changes='#'intextwhilechanges:text,changes=_back_hash.subn('',text)returntext.replace('#','')deftests():data=(("abc#def##ghi###","abd"),("abc#d##c","ac"),("abc##d######",""),("#######",""),("",""),)forinp,outindata:assertclean_text(inp)==out, \
f"{inp!r} cleaned is not {out!r} but {clean_text(inp)!r}"print('All tests OK!')if__name__=='__main__':forxin('abc#de##c','abc####dhh##c#','Thee# Empires# SS#tateBuildingg#'):print(f"{x!r} ⇒ {clean_text(x)!r}")tests()
Python – No doc strings etc., it's a challenge after all…
This is always a good idea to comment your code. Beginners trying to solve these challenges can learn a lot from veterans like you!