Towns in Order
Python
25 pts
Towns in Order
Using the list towns, create three new lists or values. The list towns itself must stay unchanged, so use sorted().
by_length— the towns sorted from shortest to longest name (key=len).longest— the last item ofby_length.reverse_alpha— the towns in reverse alphabetical order (Z to A).
Print the three. Expected output:
['Keren', 'Nakfa', 'Assab', 'Asmara', 'Massawa', 'Mendefera'] Mendefera ['Nakfa', 'Mendefera', 'Massawa', 'Keren', 'Assab', 'Asmara']
Checklist
- Keep the list
townsunchanged. - Create
by_length, the towns sorted from shortest to longest name. - Create
longest, the last item ofby_length. - Create
reverse_alpha, the towns from Z to A. - Print the three results.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
