← Back to challenges

Neighboring Letters

PythonHardhigher_order_functionslanguage_fundamentalsformattingloopsvalidation

Instructions

Create a function that takes a string and checks if every single character is preceded and followed by a character adjacent to it in the english alphabet.

Example: "b" should be preceded and followed by ether "a" or "c" (abc || cba || aba || cbc == True but abf || zbc == False).

Examples

neighboring("aba") ➞ True

neighboring("abcdedcba") ➞ True

neighboring("efghihfe") ➞ False

neighboring("abc") ➞ True

neighboring("qrstuv") ➞ True

neighboring("mnopqrstsrqponm") ➞ True

Notes

All test cases will consist of lower case letters only.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.