Python Forum
function for a single string number of syllables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function for a single string number of syllables
#1
I have a function who takes a single string as argument and returns the number of syllables of some string e.g. str = "I eat pancakes"
But i do not get the correct number of syllables what do I do wrong here? 
I use regular expression module and already got a pattern that describes the syllables in some text
def count_syllables(str):
    pattern = re.compile("[aiouy]+e*|e(?!d\b|ly)[aiouye]?|[td]ed|le\b")

    match_new = pattern.match(str.lower())
    if match_new:
        print len(string)
Reply


Messages In This Thread
function for a single string number of syllables - by tebirkes - Nov-02-2016, 01:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Extracting Version Number from a String britesc 2 1,219 May-31-2023, 10:20 AM
Last Post: britesc
  Need help on how to include single quotes on data of variable string hani_hms 5 2,274 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python sql query single quote in a string mg24 1 1,177 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 5,064 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,719 May-13-2022, 07:28 PM
Last Post: mikepy
  Checking the number of arguments a function takes Chirumer 3 2,269 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 5,363 May-02-2021, 03:45 PM
Last Post: Anldra12
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,533 Apr-11-2021, 11:03 PM
Last Post: lastyle
  cursor.execute: How to insert dynamic number in a string? stoeberhai 2 3,639 Mar-18-2021, 12:55 PM
Last Post: stoeberhai
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,487 Jan-15-2021, 04:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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