-1

I am struggling to get a good code for below transformation

From: (S (S (pomp:stem) (ous:suffix)) (ly:suffix))

To: (S (S (STEM pomp) (SUFFIX ous)) (SUFFIX ly))

Stem/suffix/prefix are standard terms while pomp/ous/ly will vary for each word. I have 1000+ such rows which needs to be transformed . I tried regex match/findall with series of steps but not getting a clean results. Is there a quick way to solve this?

broomba
  • 35
  • 4
Mandy1999
  • 9
  • 2

1 Answers1

0

you could do:

import re
a = '(S (S (pomp:stem) (ous:suffix)) (ly:suffix))'
re.sub(r"(\w+):(\w+)",lambda x: x.group(2).upper()+' '+x.group(1),a)
'(S (S (STEM pomp) (SUFFIX ous)) (SUFFIX ly))'
Onyambu
  • 31,432
  • 2
  • 14
  • 36