fork(2) download
  1. strng = '[5, 42, [19, 3, 5, [7, 7, 5]], 42, 3.14, [6,6,6,7], 2,71, 0,0]'
  2. level = 0
  3. cnt = 0
  4. for c in strng:
  5. if c == '[':
  6. cnt+=1
  7. elif c == ']':
  8. cnt-=1
  9. if cnt > 0:
  10. level+=1
  11. print (level)
  12.  
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
3