class Solution(object): def __init__(self): self.List = list() def rdfs(self,S): if S != '': length = len(S) depth = len(self.List) tempval = '' tempdepth = 0 for i in range(length): s = S[i] if s != '-': tempval += s if i == length - 1: while depth…