Parse a list of lists into a Sad-List In this challenge, you must parse a list of lists, into a simpler list format.

This challenge is based on my sadflak parser. In my sadflak parser, it has all the () removed, replaced with the sum of the ()s at the start of the list, to make the program run faster.

To parse into a Sad-List, you have to do this (python implementation thing, uses a tuple of tuples):

def sadlistfunc(list):
    new-sadlist = [0]
    for i in list:
        if i == ():
            new-sadlist[0]+=1
        else:
            new-sadlist.append(sadlistfunc(i))


This is a recursive function. For a list, start a new list, starting with the number of () from the list input, then the rest of this list is sad-list versions of every list that was not a () from the list input, in order. return the list.

Input:

you may take input in a few different formats:


you may take it as a list
you may take it as a tuple
you may take it as a string


if you take it as a string, you should use some set of brackets, as appear in brain-flak. you may not use characters 1 and 2

just be reasonable

Input will always be inside one list, but your program may assume an implicit list layer outside of the input, i.e. ()()() = (()()()), or it may choose not to. Examples will be with explicit outside list

output:

may be list or tuple or string, or whatever. you may use whatever reasonable output format, as is the meta consensus.

Example:

(()()()) = [3]
(((()))) = [0,[0,[1]]]
((())()(())) = [1, [1], [1]]
() = invalid input, if the outside bracket is explicit.
((((())())())(())()) = [1, [1, [1, [1]]], [1]]


note that input is not strict. these inputs could be:

[[],[],[]]
[[[[]]]]
[[[]],[],[[]]]
[]
[[[[[]],[]],[]],[[]],[]]


or some other reasonable format

explained test case:

(()()((())())())


to "sadify" this, first we count the number of ()

 ()()        ()
(    ((())())  )


3. then we remove these, and add a 3 at the start

(3,((())()))


there is one list in this list. we sadify this

((())())


how many ()?

     ()
((())  )


1. we remove and add a 1 at the start

(1,(()))


this has one list in it

(())


count

 ()
(  )


remove and add count

(1)


then we put this back into its list

(1,(1))


then we put this back into its list

(3,(1,(1)))


done

This is code-golf, so shorter is better
Pyth, 13 bytes

L+]/bYyM-b]Yy


Test suite.

How it works

L+]/bYyM-b]Yy
L               define a function y with argument b:
   /bY              list 1: count how many [] can be found in b
  ]                         wrap into singleton
        -b]Y        list 2: filter out [] from b
      yM                    apply y (this function) to each
 +                  concatenate the two lists above
            y   apply y to the input