python - How to do conditional character replacement within a string -


I have a Unicode string in Python and basically need to go based on the characters, and depending on the characters Replace Some People Rules One such rule is that a is converted to ö , if a is followed by n . In addition, if the line has two vowels, then they are replaced by a vowel and : . So if I have string "natrek", then what is the easiest and most effective way to get "nötaro: k" ?

Edit: Two vowels in one line mean the same vowel (o, aai, ii)

  # - * - coding: UTF-8 - * - Diff subpacer (s, prefix, suffix): deaf sub (i, sent = object)): r = prefix.get (s [ I: i + 2], transmitted) if r is not sentinal: return rr = suffix.get (s [i-1: i + 1], sentinal) if r is not sentinal: return r returns s [i] s = '\ 0' + s + '\ 0' return ' Prefix = {} suffix = {'no' in the array (1, lane (s)) for i (sub (i)) vowel = [(v + v), 'aiu'] for 'aiu' : U'o '} suffix.update (vowel) print subpair (' naturook ', prefix, suffix) # print: notro: K prefix = {' na ': u'o'} suffix = dict (vice) print subpair ( 'Natrek', prefix, suffix) # print: otao: s  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -