Last active
October 3, 2019 16:54
-
-
Save bhishanpdl/c7f2520e6856d5ea0e600b911a972f5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lst1 = [1,2,3,4,5,6,7] | |
lst2 = [4,5,6,7,1,2,3] | |
def rotation(lst1, lst2): | |
# check equal length | |
if len(lst1) != len(lst2): | |
return False | |
# keys | |
key = lst1[0] # first element of lst1 | |
key_index = 0 # index of that key in lst2 | |
# get key index from lst2 | |
for i in range(len(lst2)): | |
if lst2[i] == key: | |
key_index = i | |
break | |
# use modulo operator to compare two lists rotation | |
for i in range(len(lst1)): | |
l2index = (key_index + i) % len(lst1) | |
if lst1[i] != lst2[l2index]: | |
return False | |
return True | |
rotation(lst1, lst2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment