Python Forum
counting characters in an object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
counting characters in an object
#4
There are no literals. I just used "chars" in place of your "o".

You'd need to add in some conditional to handle the cases when the match doesn't succeed, and you might need to convert your object with characters to a string. But after that, the match is good.

def runlen(s, o):
    return re.search(fr"[^{o}]", s).span()[0]
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,840 May-15-2020, 01:37 PM
Last Post: snippsat
  Counting number of characters in a string Drone4four 1 3,466 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