if l1 == l2:
    return True
if len(l2) != len(l1):
    return False
if set(l1).difference(l2):
    return False
l2, l1 = deque(l2), deque(l1)
for i in range(len(l1)):
    l2.rotate()
if l1 == l2:
    return True
return False
Check if a list is a rotation of another list that works with duplicates