| Bytes | Lang | Time | Link |
|---|---|---|---|
| 014 | Vyxal 3 Ṡ | 250727T212645Z | pacman25 |
| 155 | Python | 220604T074636Z | Alice F |
Vyxal 3 -Ṡ, 14 bytes
Ꮬ[]⟒⑵↻Ꮬ],⨪r1ri
Vyxal It Online!
Ṡ flag doesn't eval inputs which is nice for string representations of lists
Explanation:
Ꮬ[]⟒⑵↻Ꮬ],⨪r1r⎇fj
Ꮬ[] # String `[]`
⟒ # Left fork doesn't pop the top of the stack here
⑵↻ r # replace `][` with
Ꮬ],⨪ # bracket palindromised `],` -> `],[`
1r # replace all `[]` with 1
⎇f # flatten `[]` into a list
j # join those by the inner part
💎
Created with the help of Luminespire.
tldr - left fork regex
-2 because I was looking through documentation for new stuff and noticed that i also just encloses stuff so this works out nicely
Python, 236 155 bytes
def r(o):
v="[";s=a=n=0
for c in o:
if c=="(":
if s<1:a=n+1
s+=1
else:
s-=1
if a==n:v+="1,"
elif s<1:v+=r(o[a:n])
n+=1
return v+"]"
Is this a good solution? No. But I don't think there'll be another answer here soon, and I'm very new to codegolf so I thought I might try my luck here :p