Workout #13: Printing Tuple Records

Sep 28, 2021

For example, assume we’re in charge of an international summit in London. We know how many hours it’ll take each of several world leaders to arrive:

PEOPLE = [('Donald', 'Trump', 7.85),
('Vladimir', 'Putin', 3.626),
('Jinping', 'Xi', 10.603)]

The planner for this summit needs to have a list of the world leaders who are coming, along with the time it’ll take for them to arrive. However, this travel planner doesn’t need the degree of precision that the computer has provided; it’s enough for us to have two digits after the decimal point.

For this exercise, write a Python function, format_sort_records, that takes the PEOPLE list and returns a formatted string that looks like the following:

Trump      Donald      7.85
Putin Vladimir 3.63
Xi Jinping 10.60

TRY IT YOURSELF

ANSWER

https://colab.research.google.com/drive/1AuP_da5XYEdFire5vrE1nO0eSxegq1fL?usp=sharing

--

--

Abish Pius
Abish Pius

Written by Abish Pius

Data Science Professional, Python Enthusiast, turned LLM Engineer

No responses yet