Skip to content

Instantly share code, notes, and snippets.

@Slyfoxnick Slyfoxnick/substring_between.py Secret

Last active Mar 6, 2020
Embed
What would you like to do?
# Write your substring_between_letters function here:
def substring_between_letters(word, start, end):
if start == end and word.find(start) != -1:
start = word.find(start) + 1
end = word.find(end, start)
return word[start:end]
start = word.find(start) + 1
end = word.find(end)
if end < start:
start, end = end + 1, start -1
if start != 0 and end != -1:
return word[start:end]
return word
# Uncomment these function calls to test your function:
print(substring_between_letters("apple", "p", "e"))
# should print "pl"
print(substring_between_letters("apple", "p", "c"))
# should print "apple"
print(substring_between_letters("apple", "e", "p"))
# should print "pl"
print(substring_between_letters("mountain", "n", "n"))
# should print "tai"
print(substring_between_letters("test", "x", "y"))
# should return "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.