Python Forum
counting characters in an object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
counting characters in an object
#1
i have a string (str,bytes,bytearray) and an object with one or more characters (str,bytes,bytearray,set,frozenset,list,tuple). the beginning of the string has some number of characters that would get a True result if the in operator is used with that object while stepping through the string until it reaches a character that would get False. as this is hard to explain, here is some code:
def runlen(s,o):
    for n in range(len(s)):
        if s[n] in o:
            continue
        return n
what i would like to know is if there is a way to call something to do that loop internally so it would run faster. maybe re can do this, somehow. once i have the position n, i will be using s[:n] though not s[n:]. so, something that just gives me the prefix would do the job.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
counting characters in an object - by Skaperen - May-31-2020, 01:51 AM
RE: counting characters in an object - by bowlofred - May-31-2020, 02:33 AM
RE: counting characters in an object - by Skaperen - May-31-2020, 03:17 AM
RE: counting characters in an object - by bowlofred - May-31-2020, 03:30 AM
RE: counting characters in an object - by Skaperen - May-31-2020, 10:03 AM
RE: counting characters in an object - by Skaperen - Jun-01-2020, 11:30 PM
RE: counting characters in an object - by Skaperen - Jun-08-2020, 07:35 PM
RE: counting characters in an object - by Skaperen - Jun-09-2020, 07:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,761 May-15-2020, 01:37 PM
Last Post: snippsat
  Counting number of characters in a string Drone4four 1 3,454 Aug-16-2018, 02:33 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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