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 <[email protected]> wrote: > On Sat, 3 Jun 2023 at 07:08, David Mertz, Ph.D. <[email protected]> > 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 -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/3EK66S27AO2IFBWPOIJ6ABUEJ6C6W2YB/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/DJXKMQNXP4O23LHN43YAVL4XSWUSWMUT/ Code of Conduct: http://python.org/psf/codeofconduct/
