fork download
  1. consonants = 'bdfhjklmnprstvwzðŋɡʃʒθ'
  2. vowels = 'aeiouæɑʊɔɪɛʌəᵻː'
  3. stress_marks = 'ˈˌ'
  4.  
  5. def abugidafy(word):
  6. # Dict from (x, y) to characters.
  7. tiles = dict()
  8. x = y = 0
  9.  
  10. is_first = True
  11. for c in word:
  12. if c in stress_marks:
  13. tiles[x + 1, 1] = c
  14. elif c in consonants or is_first:
  15. y = 0
  16. x += 1
  17. tiles[x, y] = c
  18. is_first = False
  19. elif c in vowels:
  20. y -= 1
  21. tiles[x, y] = c
  22. is_first = False
  23. else:
  24. raise ValueError('Not an IPA character: ' + c)
  25.  
  26. xs = [x for (x, y) in tiles.keys()]
  27. ys = [y for (x, y) in tiles.keys()]
  28. xmin, xmax = min(xs), max(xs)
  29. ymin, ymax = min(ys), max(ys)
  30.  
  31. lines = []
  32. for y in range(ymin, ymax + 1):
  33. line = [tiles.get((x, y), ' ') for x in range(xmin, xmax + 1)]
  34. lines.append(''.join(line))
  35. return '\n'.join(lines)
  36.  
  37. print(abugidafy(input()))
Success #stdin #stdout 0.01s 9992KB
stdin
ˌsuːpərˌkaləˌfrædʒəˌlɪstɪˌkɛkspiːæləˈdoʊʃəs
stdout
               æ    
ː              ː ʊ  
uə aə æ əɪ ɪɛ  iəoə 
sprklfrdʒlstkkspldʃs
ˌ  ˌ ˌ   ˌ  ˌ    ˈ