Есть ли разница в написании что-то вроде 33 <= cp <= 47
против cp >= 33 and cp <= 47
?
Более конкретно, если есть функция, которая выполняет:
def _is_punctuation(char):
"""Checks whether `chars` is a punctuation character."""
cp = ord(char)
if ((cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or
(cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126)):
return True
else:
return False
, это то же самое, что:
def is_punctuation(char):
"""Checks whether `chars` is a punctuation character."""
# Treat all non-letter/number ASCII as punctuation.
# Characters such as "^", "$", and "`" are not in the Unicode
# punctuation class but treat them as punctuation anyways, for consistency.
cp = ord(char)
if (33 <= cp <= 47) or (58 <= cp <= 64) or (91 <= cp <= 96) or (123 <= cp <= 126):
return True
return False
Есть ли причины предпочитать _is_punctuation()
сверх is_punctuation()
или наоборот?
Будет ли один вычислительно быстрее другого? Если так, как мы можем это проверить? Используя dis.dis
?
P / S: Я задаю вопрос, потому что не могу найти причину, по которой инженеры Google AI предпочитают оригинальную реализацию _is_punctuation
на https://github.com/google-research/bert/blob/master/tokenization.py#L386