How about:

word = "Almuta$r~id"
predecessors = "_" * 5
successors = "".join(letter for letter in word if letter not in "aiou+~")
for index, letter in enumerate(word):
 if letter not in "aiou~+":
   next = word[index+1] if index < len(word) - 1 else ""
   if next in "aiou":
     tail = next
   elif next == "~":
next = word[index+2] # bold assumption that a short vowel will follow ~
     tail = "~" + next
   else:
     tail = "_"
   print predecessors + successors + tail
   predecessors = predecessors[1:] + letter
   successors = successors[1:] + ("_" if len(successors) <= 5 else "")

Simple - procedural - no functions. 16 lines of code. Easy to read and maintain.

--
Bob Gailer
Chapel Hill NC 919-636-4239

When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to