Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Last active August 26, 2017 20:27
Show Gist options
  • Save ryanorsinger/c313142b6e6a6edbe676 to your computer and use it in GitHub Desktop.
Save ryanorsinger/c313142b6e6a6edbe676 to your computer and use it in GitHub Desktop.
States

Reading a CSV file and parsing the results

Topics

  • Reading files
  • Iterating across a map of keys and values
  • Parsing results

Setup

  • Download a copy of the states.csv file into your exercises/project directory of your choice.
  • Use the programming language of your choice to solve the following problems.

Exercises:

  1. Write a function that returns the state with the longest name.
  2. Write a function that produces a copy of the abbreviations/state names in alphabetical order based on the abbreviation.
  3. Write a function that returns a list of only the abbreviations.
  4. Write a function that returns a list of only the state names in order of the number of characters from low to high.
AL Alabama
AK Alaska
AZ Arizona
AR Arkansas
CA California
CO Colorado
CT Connecticut
DE Delaware
DC District of Columbia
FL Florida
GA Georgia
HI Hawaii
ID Idaho
IL Illinois
IN Indiana
IA Iowa
KS Kansas
KY Kentucky
LA Louisiana
ME Maine
MD Maryland
MA Massachusetts
MI Michigan
MN Minnesota
MS Mississippi
MO Missouri
MT Montana
NE Nebraska
NV Nevada
NH New Hampshire
NJ New Jersey
NM New Mexico
NY New York
NC North Carolina
ND North Dakota
OH Ohio
OK Oklahoma
OR Oregon
PA Pennsylvania
PR Puerto Rico
RI Rhode Island
SC South Carolina
SD South Dakota
TN Tennessee
TX Texas
VI US Virgin Islands
UT Utah
VT Vermont
VA Virginia
WA Washington
WV West Virginia
WI Wisconsin
WY Wyoming
<?php
$states = array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District of Columbia',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'PR' => 'Puerto Rico',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'VI' => 'US Virgin Islands',
'UT' => 'Utah',
'VT' => 'Vermont',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment