-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender_toy.py
More file actions
40 lines (33 loc) · 914 Bytes
/
render_toy.py
File metadata and controls
40 lines (33 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def render_function(context, do_dots):
c_name = context["name"]
c_products = context["products"]
c_lower = context["lower"]
result = []
append_result = result.append
extend_result = result.extend
to_str = str
extend_result([
"<p> Welcome, ",
to_str(c_name),
"! </p>\n<p> Products:</p>\n<ul>\n",
])
# for block
for c_product in c_products:
extend_result([
"<li> ",
to_str(c_lower(do_dots(c_product, "name"))),
": $",
to_str(do_dots(c_product, "price")),
"</li>\n"
])
append_result("\n</ul>")
return "".join(result)
products = {"Apple": 1.00,
"Fig": 1.50,
"Pomegranate": 3.25}
print(render_function(
{"name": "Hafs",
"products": products,
"lower": str.lower},
lambda x,y: x if y == "name" else products[x]
))