← Back to challenges

State Names and Abbreviations

PythonHardarraysformattingloops

Instructions

Create a function that filters out a list of state names into two categories based on the second parameter.

  1. Abbreviations abb
  2. Full names full

Examples

filter_state_names(["Arizona", "CA", "NY", "Nevada"], "abb")
➞ ["CA", "NY"]

filter_state_names(["Arizona", "CA", "NY", "Nevada"], "full")
➞ ["Arizona", "Nevada"]

filter_state_names(["MT", "NJ", "TX", "ID", "IL"], "abb")
➞ ["MT", "NJ", "TX", "ID", "IL"]

filter_state_names(["MT", "NJ", "TX", "ID", "IL"], "full")
➞ []

Notes

State abbreviations will always be in uppercase.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Is the Average of All Elements a Whole Number?