verifying an alien dictionary

Go Back home
 1 order = "hlabcdefgijkmnopqrstuvwxyz"
 2 
 3 def isAlienSorted(words, order):
 4   for w1, w2 in zip(words, words[1:]):
 5     for a, b in zip(w1, w2):
 6       oa = order.index(a) 
 7       ob = order.index(b)
 8       if oa > ob:
 9         return False
10       elif oa == ob:
11         pass
12       else:
13         break
14     else:
15       if len(w1) > len(w2):
16         return False
17 
18   return True
19 
20 assert isAlienSorted(["hello","leetcode"], "hlabcdefgijkmnopqrstuvwxyz") == True
21 assert isAlienSorted(["word","world","row"], "worldabcefghijkmnpqstuvxyz") == False
22 assert isAlienSorted(["aaa","bbb","ccc"], "abc") == True
23 assert isAlienSorted(["aba","bab","cac"], "abc") == True
24 assert isAlienSorted(["aaa","aab","aac"], "abc") == True
25 assert isAlienSorted(["aaa","aa","aac"], "abc") == False

alien dictionary