CoCalc Public Filestmp / a.pyOpen in with one click!
Authors: Harald Schilly, ℏal Snyder, William A. Stein
1
import re
2
def multiple_replace(txt, adict):
3
rx = re.compile('|'.join(map(re.escape, adict)))
4
def one_xlat(match):
5
return adict[match.group(0)]
6
return rx.sub(one_xlat, txt)
7
8
txt = "Larry Wall is the жчины creator of Perl"
9
10
adict = {
11
"Larry Wall" : "Guido van Rossum",
12
"creator" : "Benevolent Dictator for Life",
13
"Perl" : "Python",
14
}
15
16
print(multiple_replace(txt, adict))
17
18
t = """
19
︠54e9f279-48e9-4e99-8fe8-be313ce926cbs︠
20
%load a.py
21
︡36d2e33b-6f22-41b3-9466-53a76af8626c︡︡{"stdout":"Guido van Rossum is the жчины Benevolent Dictator for Life of Python\n","done":false}︡{"done":true}
22
︠1032ce2e-8fa8-411b-89fb-45353d0a7cccs︠
23
show(LatexExpr("x^2"))
24
︡ffdee0a7-ca5d-4b44-a5c2-a8b174b132ae︡︡{"html":"<div align='center'>x^2</div>","done":false}︡{"done":true}
25
︠264fc892-9fdd-41b7-a09a-0fa87e98e805s︠
26
show(latex(x^2))
27
︡34542d7d-285f-4461-8e41-73c868aef4c7︡︡{"html":"<div align='center'>x^{2}</div>","done":false}︡{"done":true}
28
︠37fbff20-9f12-4203-8930-40ebefe05ec0s︠
29
math.sin?
30
︡9b801259-3e73-46ae-8108-b83a911cd14b︡︡{"code":{"source":"File: \nSignature : math.sin()\nDocstring :\nsin(x)\n\nReturn the sine of x (measured in radians).","mode":"text/x-rst","lineno":-1,"filename":null},"done":false}︡{"done":true}
31
︠cf71978f-6a17-4800-bca1-9e827c6341c5︠
32
InteractiveLPProblemStandardForm(
33
︠22e3d542-7169-48d9-bc67-45990f4dd689︠
34
%latex
35
36
\begin{enumerate}
37
\item
38
\end{enumerate}
39
40
41
︠992415fd-333e-43bb-827a-c4fe6d688150s︠
42
2+3
43
︡5019412d-20cd-4917-9fe7-173345b5147e︡︡{"stdout":"5\n","done":false}︡{"done":true}
44
︠bf498d1d-b9af-4268-bf97-d7d472131bdbos︠
45
4+5
46
︡28aec6c3-a386-4cc3-aa10-8018950abd77︡︡{"stdout":"9\n","done":false}︡{"done":true}
47
︠3deab854-9c3e-45f6-9985-003377781fd3︠
48
49
50
51
52
53
54
55
56
57
"""