Python Forum
str.startswith(tuple) ... which start?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.startswith(tuple) ... which start?
#2
I would perhaps use bisect for this, if the tuple is sorted
>>> import bisect
>>> t = ('bar', 'baz', 'foo')
>>> w = 'bazaaa'
>>> w.startswith(t)
True
>>> index = bisect.bisect_right(t, w) - 1
>>> t[index]
'baz'
Reply


Messages In This Thread
RE: str.startswith(tuple) ... which start? - by Gribouillis - May-26-2020, 06:32 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020