def uniq(base, l):
    nl = []
for i in l:
    if type(i) is list:
        nl.append(uniq(base, i))
else:
    nl.append(base)
return nl
More elegant way to initialize list of duplicated items in Python