trunc_1.py 530 B

1234567891011121314151617181920
  1. def smart_truncate(line):
  2. line = line.lower()
  3. for pattern, replacement in trans:
  4. line = re.sub(pattern, replacement, line)
  5. pipe_parts = line.split('|')
  6. if len(pipe_parts) > 1:
  7. line = pipe_parts[0] + '|A'
  8. for x in line.split('/'):
  9. if x in avian:
  10. line = re.sub(x, 'avian', line)
  11. double_start = line.rfind(line[1:PREFIX_LENGTH], PREFIX_LENGTH)
  12. if double_start != -1:
  13. line = line[double_start:]
  14. return line.strip().title() + '\r\n'