vowels.py (703B)
1 #!/usr/bin/python3 2 # coding: utf-8 3 4 """Compute the number of syllabes taken by a vowel chunk""" 5 6 7 def intersperse(left, right): 8 if (len(left) == 0 or left[0] == ' ') and (len(right) == 0 or right[0] == ' '): 9 return [] 10 if len(left) == 0 or left[0] == ' ': 11 return ["/", right[0]] + intersperse(left, right[1:]) 12 if len(right) == 0 or right[0] == ' ': 13 return [left[0], "/"] + intersperse(left[1:], right) 14 return [left[0], right[0]] + intersperse(left[1:], right[1:]) 15 16 17 def contains_trema(chunk): 18 """Test if a string contains a word with a trema""" 19 for x in ['ä', 'ë', 'ï', 'ö', 'ü', 'ÿ']: 20 if x in chunk: 21 return True 22 return False