On Sat, 3 Jun 2023 at 07:08, David Mertz, Ph.D. <david.me...@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-le...@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/3EK66S27AO2IFBWPOIJ6ABUEJ6C6W2YB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to