fork download
  1. s = input()
  2. if len(s.split(',')) < 2:
  3. cor = s.count(' or ')
  4. cand = s.count(' and ')
  5. cnor = s.count(' nor ')
  6. if cor + cand + cnor > 1:
  7. ind = -min(min(-s.find(' or '), -s.find(' and ')), -s.find(' nor '))
  8. tmp = s[ind+1:]
  9. tmp = tmp.replace(' or ', ', or ')
  10. tmp = tmp.replace(' nor ', ', nor ')
  11. tmp = tmp.replace(' and ', ', and ')
  12. s = s[:ind+1] + tmp
  13. print(s)
  14. else:
  15. c = 0
  16. p = 0
  17. for i in range(len(s)-5):
  18. if s[i] == ',':
  19. c += 1
  20. p = 0
  21. continue
  22. elif (s[i-1] != ',') and ((s[i:i+4] == ' or ') or (s[i:i+5] == ' nor ') or (s[i:i+5] == ' and ')):
  23. if c > 0 and p == 1:
  24. s = s[:i] + ',' + s[i:]
  25. i += 4*(s[i:i+4] == ' or ') + 5*(s[i:i+5] == ' nor ') + 5*(s[i:i+5] == ' and ')
  26. c = 0
  27. p = 0
  28. elif s[i] == ' ':
  29. p += 1
  30. print(s)
  31.  
  32. a = 'abcdfsfsadsd'
  33. a = a.replace('d', '7')
  34. print(a, a.find('6'))
Success #stdin #stdout 0.02s 9228KB
stdin
Ann played football, tennis and chees, went home, forgot keys and her snack.
stdout
Ann played football, tennis, and chees, went home, forgot keys and her snack.
abc7fsfsa7s7 -1