Skip to content

Commit 6190241

Browse files
committed
use more idiomatic python in unicode.py
STR.join(...) is better than manual `for` loops that remember whether we've processed the first element.
1 parent 414a14f commit 6190241

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

scripts/unicode.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,8 @@ def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
220220
if is_pub:
221221
pub_string = "pub "
222222
f.write(" %sconst %s: %s = &[\n" % (pub_string, name, t_type))
223-
data = ""
224-
first = True
225-
for dat in t_data:
226-
if not first:
227-
data += ","
228-
first = False
229-
data += pfun(dat)
223+
data = [pfun(d) for d in t_data]
224+
data = ','.join(data)
230225
format_table_content(f, data, 8)
231226
f.write("\n ];\n\n")
232227

@@ -255,12 +250,8 @@ def emit_norm_module(f, canon, compat, combine, norm_props, general_category_mar
255250
def mkdata_fun(table):
256251
def f(char):
257252
data = "(%s,&[" % escape_char(char)
258-
first = True
259-
for d in table[char]:
260-
if not first:
261-
data += ","
262-
first = False
263-
data += escape_char(d)
253+
chars = [escape_char(d) for d in table[char]]
254+
data += ','.join(chars)
264255
data += "])"
265256
return data
266257
return f
@@ -276,12 +267,8 @@ def f(char):
276267
def comp_pfun(char):
277268
data = "(%s,&[" % escape_char(char)
278269
canon_comp[char].sort(lambda x, y: x[0] - y[0])
279-
first = True
280-
for pair in canon_comp[char]:
281-
if not first:
282-
data += ","
283-
first = False
284-
data += "(%s,%s)" % (escape_char(pair[0]), escape_char(pair[1]))
270+
data += ','.join("(%s,%s)" % (escape_char(pair[0]), escape_char(pair[1]))
271+
for pair in canon_comp[char])
285272
data += "])"
286273
return data
287274

0 commit comments

Comments
 (0)