Skip to content

Instantly share code, notes, and snippets.

@alexnad
Created September 29, 2014 12:29
Show Gist options
  • Select an option

  • Save alexnad/de1551bdf4f57dd3c7d3 to your computer and use it in GitHub Desktop.

Select an option

Save alexnad/de1551bdf4f57dd3c7d3 to your computer and use it in GitHub Desktop.
def ABCheck(str):
str = str.lower()
next_a = -1
next_b = -1
for position, letter in enumerate(str):
if position == next_a and letter == 'a' or position == next_b and letter == 'b':
return True
if letter == 'a':
next_a = -1
next_b = position + 4
if letter == 'b':
next_a = position + 4
next_b = -1
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment