Skip to content

Instantly share code, notes, and snippets.

@brainyfarm
Created August 8, 2016 07:28
Show Gist options
  • Save brainyfarm/003c8288dd2b971c9b40aa9970648066 to your computer and use it in GitHub Desktop.
Save brainyfarm/003c8288dd2b971c9b40aa9970648066 to your computer and use it in GitHub Desktop.
FreeCodeCamp: Confirm the Ending (Python)
"""
Check if a string (first argument, string) ends
with the given target string (second argument, target).
"""
def confirmEnding(string, target):
# Some intelligent stuff going on here
# We fing out what part of string we need to compare with target
start_reading_from = len(string) - len(target)
# String slicing and comparing
return string[start_reading_from:] == target
print confirmEnding("Open sesame", "same")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment