Sure. That's fine. With a sufficiently long strings my code is faster, but for "typical" strings yours will be. On Fri, Jun 2, 2023, 5:20 PM Chris Angelico <rosuav@gmail.com> wrote:
On Sat, 3 Jun 2023 at 07:08, David Mertz, Ph.D. <david.mertz@gmail.com> wrote:
def does_string_have_currency_mark(s): return bool(set(s) & set(unicode_categories['Sc'])
def does_string_have_numeric_digit(s): ...
... and so on. Those seem like questions one asks often enough. Not every day, but more than never.
These questions are much better answered with the unicodedata.category() function. First figure out what categories your string has:
cats = set(unicodedata.category(ch) for ch in s)
And then check whether Sc is in that set, or whatever others you care about.
This way, the set contains only the categories, not the characters; there's no reason to do set intersection with all of the characters.
ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/3EK66S... Code of Conduct: http://python.org/psf/codeofconduct/