← Back to challenges

Longest Abecedarian Word

PythonHardarraysstringsloops

Instructions

An abecedarian word is a word where all of its letters are arranged in alphabetical order. Examples of these words include:

  • Empty
  • Forty
  • Almost

Given a list of words, create a function which returns the longest abecedarian word. If no word in a list matches the criterea, return an empty string.

Examples

longest_abecedarian(["ace", "spades", "hearts", "clubs"]) ➞ "ace"

longest_abecedarian(["forty", "choppy", "ghost"]) ➞ "choppy"

longest_abecedarian(["one", "two", "three"]) ➞ ""

Notes

  • All words will be given in lowercase.
  • If two abecedarian words have the same length, return the word which appeared first in the list.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.