Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Multiple sub in single regex

	# Multiple sub in single regex.
import re
class Substitutable(str):
  def __new__(cls, *args, **kwargs):
    newobj = str.__new__(cls, *args, **kwargs)
    newobj.sub = lambda fro,to: Substitutable(re.sub(fro, to, newobj))
    return newobj
h = Substitutable('horse')
h = h.sub('h', 'f').sub('e','h')
print(h)
Comment

PREVIOUS NEXT
Code Example
Python :: jupiter output 
Python :: django form is onvalid 
Python :: ex: python arraay 
Python :: python long 
Python :: ValueError: Could not load "" Reason: "broken data stream when reading image file" 
Python :: Finding the Sum of a Symmetrical Sub-List 
Python :: pandas parameters read 
Python :: l1=[122, 5, 9, 4] l2=[991, 4, 8, 3] x=[l1[i]-l2[i] for i in range(abs(len(l1)), abs(len(l2)))] print (x) 
Python :: make a coo_matrix 
Python :: stop animation matplotlib 
Python :: Can the string find method be used to search a list? 
Python :: matplotlib show two distinct plots 
Python :: how to add to an index in a list in python 
Python :: matruzen rechner python 
Python :: how to convert 2 dimensional in 1 dimensional array 
Python :: how to serial print line break 
Python :: pandas series add prefix 
Python :: python text to speech arabic 
Python :: temp python 
Python :: unban member using ID discord.py 
Python :: sort one array based on another python 
Python :: TypeError: can only concatenate str (not "list") to str 
Python :: the range() function 
Python :: matplotlib get padding from bbox 
Python :: list comprehension python 
Python :: boolean python example 
Python :: python round function example 
Python :: pandas columns 
Python :: a python string 
Python :: migration django 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =