fork download
  1. #!/usr/bin/env python3
  2.  
  3. import re
  4.  
  5. x = 'Confirmatory factor analysis (CFA) is a special case of what is known as structural equation modelling (S.E.M.).'
  6. results = []
  7. split_regex = re.compile(r'\s+')
  8. for m in re.finditer(r'\b([A-Za-z][a-z]*(?:\s[A-Za-z][a-z]*)+)\s+\(((?:[A-Z]\.?){2,})\)', x):
  9. abbreviation = m[2]
  10. l = sum(c.isalpha() for c in abbreviation)
  11. full_form = ' '.join(split_regex.split(m[1])[-l:])
  12. results.append([full_form, abbreviation])
  13. print(results)# your code goes here
Success #stdin #stdout 0.02s 9584KB
stdin
Standard input is empty
stdout
[['Confirmatory factor analysis', 'CFA'], ['structural equation modelling', 'S.E.M.']]