Skip to content

Commit aa2a2c6

Browse files
authored
Replaced some iadd operations on lists with proper list methods. (#8433)
1 parent 026a2ff commit aa2a2c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/transformers/tokenization_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def split_on_token(tok, text):
291291
full_word += sub_text + tok
292292
elif full_word:
293293
full_word += sub_text
294-
result += [full_word]
294+
result.append(full_word)
295295
full_word = ""
296296
continue
297297
# Strip white spaces on the right
@@ -310,16 +310,16 @@ def split_on_token(tok, text):
310310
sub_text = sub_text.lstrip()
311311

312312
if i == 0 and not sub_text:
313-
result += [tok]
313+
result.append(tok)
314314
elif i == len(split_text) - 1:
315315
if sub_text:
316-
result += [sub_text]
316+
result.append(sub_text)
317317
else:
318318
pass
319319
else:
320320
if sub_text:
321-
result += [sub_text]
322-
result += [tok]
321+
result.append(sub_text)
322+
result.append(tok)
323323
return result
324324

325325
def split_on_tokens(tok_list, text):
@@ -334,9 +334,9 @@ def split_on_tokens(tok_list, text):
334334
tokenized_text = []
335335
for sub_text in text_list:
336336
if sub_text not in self.unique_no_split_tokens:
337-
tokenized_text += split_on_token(tok, sub_text)
337+
tokenized_text.extend(split_on_token(tok, sub_text))
338338
else:
339-
tokenized_text += [sub_text]
339+
tokenized_text.append(sub_text)
340340
text_list = tokenized_text
341341

342342
return list(

0 commit comments

Comments
 (0)