fork download
  1. import re
  2. def iterative(s):
  3. stack = ['']
  4. for token in re.findall(r'[,\[\]]|.+?', s):
  5. if token == '[':
  6. stack.append('')
  7. elif token == ']':
  8. if stack[-1]:
  9. yield '.'.join(stack)
  10. stack.pop()
  11. stack[-1] = ''
  12. elif token == ',':
  13. if stack[-1]:
  14. yield '.'.join(stack)
  15. else:
  16. stack[-1] = token
  17. if stack and stack[0]:
  18. yield ''.join(stack)
  19.  
  20.  
  21. s = 'a,b,c[a,b,c[a]],d'
  22. print(list(iterative(s)))
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
['a', 'b', 'c.a', 'c.b', 'c.c.a', 'd']