Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # regex fix
- def f(s):
- for e,b in p:
- if b[1:]:s=re.sub(b,f'[{b}{e}]',s)
- for e,b in p:
- if b>b[1:]:s=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s)
- return s
- # more repeated code
- def f(s):
- for e,b in p:
- if b[1:]:s=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s)
- for e,b in p:
- if b>b[1:]:s=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s)
- return s
- # Python 3.8
- def f(s):
- [(s:=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s))for e,b in p if b[1:]]
- [(s:=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s))for e,b in p if b[1:]<b]
- return s
- # lambda
- lambda s:[(s:=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s))for e,b in p if b[1:]]and[(s:=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s))for e,b in p if b[1:]<b][-1]
- # use repeated code
- f=eval("lambda s:_]and_<b][-1]".replace('_',"[(s:=re.sub(f'(?<!\[){b}',f'[{b}{e}]',s))for e,b in p if b[1:]"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement