39Sorting Records

When you’re looking at results, you’ll want to be able to sort them so you can find what you’re looking for quickly or do some quick visual comparisons.

Given the following data set

First Name

Last Name

Position

Separation date

John

Johnson

Manager

2016-12-31

Tou

Xiong

Software Engineer

2016-10-05

Michaela

Michaelson

District Manager

2015-12-19

Jake

Jacobson

Programmer

Jacquelyn

Jackson

DBA

Sally

Weber

Web Developer

2015-12-18

create a program that sorts all employees by last name and prints them to the screen in a tabular format.

Example Output

 
Name | Position | Separation Date
 
--------------------|-------------------|----------------
 
Jacquelyn Jackson | DBA |
 
Jake Jacobson | Programmer |
 
John Johnson | Manager | 2016-12-31
 
Michaela Michaelson ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.