class link:
def __init__(self, val, next=None):
self.val=val
self.next=next
def append(self, val):
self.next={'val':val, 'next':self.next}
a = head
k = []
while a!=None:
k.append(a.val)
a = a.next
m = link(k[-1])
for i in range(len(k)-1):
m.append(k[i])
return m.__dict__