a linked list is given such that each node contains an additional random pointer which could point to any node in the list or null return a deep copy of the list type head randomlistnode rtype randomlistnode on type head randomlistnode rtype randomlistnode type head randomlistnode rtype randomlistnode o n type head randomlistnode rtype randomlistnode
from collections import defaultdict


class RandomListNode(object):
    def __init__(self, label):
        self.label = label
        self.next = None
        self.random = None


def copy_random_pointer_v1(head):
    
    dic = dict()
    m = n = head
    while m:
        dic[m] = RandomListNode(m.label)
        m = m.next
    while n:
        dic[n].next = dic.get(n.next)
        dic[n].random = dic.get(n.random)
        n = n.next
    return dic.get(head)



def copy_random_pointer_v2(head):
    
    copy = defaultdict(lambda: RandomListNode(0))
    copy[None] = None
    node = head
    while node:
        copy[node].label = node.label
        copy[node].next = copy[node.next]
        copy[node].random = copy[node.random]
        node = node.next
    return copy[head]