Python coding #1

Leetcode 796. Rotate String

Posted by Minyoung Jeong on September 09, 2020
We are given two strings, A and B.

A shift on A consists of taking string A and moving the leftmost character to the rightmost position. 
For example, if A = 'abcde', then it will be 'bcdea' after one shift on A. 
Return True if and only if A can become B after some number of shifts on A.

Example 1:
Input: A = 'abcde', B = 'cdeab'
Output: true

Example 2:
Input: A = 'abcde', B = 'abced'
Output: false
Note:

A and B will have length at most 100.  
  

My solution:

def checker(A, B):
  ## immediately return True if both A and B are equal to each other ##
  if A == B:
    return True

  ## immediately return False if the length of A and B are different ##
  if len(A) != len(B):
    return False

  ## going through a for loop to start looking from the 1st element in string B and gradually increases looking upto "X"th element (conversely looking down to "X"th element
    in string A) and see if the sliced A and B strings are equal to each other ## 
    
  for x in range(1,len(A)):
     if B[:x] == A[len(A) - x:]:
         return True
  return False