Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/69bc6cb30c1d112a2e110a04.md
T

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69bc6cb30c1d112a2e110a04 Challenge 247: Last Letter 29 challenge-247

--description--

Given a string, return the letter from the string that appears last in the alphabet.

  • If two or more letters tie for the last in the alphabet, return the first one.
  • Ignore all non-letter characters.

--hints--

get_last_letter("world") should return "w".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_last_letter("world"), "w")`)
}})

get_last_letter("Hello World") should return "W".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_last_letter("Hello World"), "W")`)
}})

get_last_letter("The quick brown fox jumped over the lazy dog.") should return "z".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_last_letter("The quick brown fox jumped over the lazy dog."), "z")`)
}})

get_last_letter("HeLl0") should return "L".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_last_letter("HeLl0"), "L")`)
}})

get_last_letter("!#$ er@R asd fT.,> 2t0e9") should return "T".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_last_letter("!#$ er@R asd fT.,> 2t0e9"), "T")`)
}})

--seed--

--seed-contents--

def get_last_letter(s):

    return s

--solutions--

def get_last_letter(s):
    letters = [c for c in s if c.isalpha()]
    return max(letters, key=lambda c: c.lower())