::: {#navbar .navbar .navbar-default .navbar-fixed-top role="navigation"}
::: {.container}
::: {.navbar-header}
[]{.icon-bar} []{.icon-bar} []{.icon-bar}

<div>

[![](../_static/img/RAIcon.png)](/runestone/default/user/login){.brand-logo}
[fopp](../index.html){#rs-book-toc-link .navbar-brand}

</div>
:::

::: {.navbar-collapse .collapse .navbar-ex1-collapse}
-   
-   []{#ad_warning}
-   []{#browsing_warning}
-   
-   [*[Search]{.visuallyhidden
    aria-label="Search"}*](#){.dropdown-toggle}
    -   [Table of Contents](../index.html)

    -   [Book Index](../genindex.html)

    -   

    -   ::: {.input-group}
        :::
-   
-   [*[User]{.visuallyhidden aria-label="User"}*](#){.dropdown-toggle}
    -   []{.loggedinuser}

    -   

    -   [Course Home](/ns/course/index)

    -   [Assignments](/assignment/student/chooseAssignment)

    -   [Practice](/runestone/assignments/practice)

    -   [[Peer Instruction
        (Instructor)](/runestone/peer/instructor.html)]{#inst_peer_link}

    -   [Peer Instruction (Student)](/runestone/peer/student.html)

    -   

    -   [Change Course](/runestone/default/courses)

    -   

    -   [[Instructor\'s
        Page](/runestone/admin/index)]{#ip_dropdown_link}

    -   [Progress Page](/runestone/dashboard/studentreport)

    -   

    -   [Edit Profile](/runestone/default/user/profile){#profilelink}

    -   [Change
        Password](/runestone/default/user/change_password){#passwordlink}

    -   [Register](/runestone/default/user/register){#registerlink}

    -   [Login](#)

    -   ::: {.slider .round}
        :::

        Dark Mode
-   
-   [[*[Scratch Activecode]{.visuallyhidden
    aria-label="Scratch Activecode"}*](javascript:runestoneComponents.popupScratchAC())]{#scratch_ac_link}
-   
-   [*[Help]{.visuallyhidden aria-label="Help"}*](#){.dropdown-toggle}
    -   [FAQ](http://runestoneinteractive.org/pages/faq.html)
    -   [Instructors Guide](https://guide.runestone.academy)
    -   
    -   [About Runestone](http://runestoneinteractive.org)
    -   [Report A
        Problem](/runestone/default/reportabug?course=fopp&page=ChapterAssessment)
-   

```{=html}
<!-- -->
```
-   
-   [This Chapter](../index.html){.dropdown-toggle}
    -   [16.1 Introduction: Sorting with Sort and
        Sorted](intro-SortingwithSortandSorted.html){.reference
        .internal}
    -   [16.2 Optional reverse
        parameter](Optionalreverseparameter.html){.reference .internal}
    -   [16.3 Optional key
        parameter](Optionalkeyparameter.html){.reference .internal}
    -   [16.4 Sorting a Dictionary](SortingaDictionary.html){.reference
        .internal}
    -   [16.5 Breaking Ties: Second
        Sorting](SecondarySortOrder.html){.reference .internal}
    -   [16.6 👩‍💻 When to use a Lambda
        Expression](WPWhenToUseLambdaVsFunction.html){.reference
        .internal}
    -   [16.7 Glossary](Glossary.html){.reference .internal}
    -   [16.8 Exercises](Exercises.html){.reference .internal}
    -   [16.9 Chapter Assessment](ChapterAssessment.html){.reference
        .internal}
-   
-   
:::
:::
:::

::: {#continue-reading .container}
:::

::: {#main-content .container role="main"}
::: {#adcopy_1 .adcopy style="display: none;"}
#### Before you keep reading\...

Runestone Academy can only continue if we get support from individuals
like you. As a student you are well aware of the high cost of textbooks.
Our mission is to provide great books to you for free, but we ask that
you consider a \$10 donation, more if you can or less if \$10 is a
burden.

::: {.donateb}
[Support Runestone Academy Today](/runestone/default/donate?ad=1){.btn
.btn-info}
:::

::: {#adcopy_2 .adcopy style="display: none;"}
#### Before you keep reading\...

Making great stuff takes time and \$\$. If you appreciate the book you
are reading now and want to keep quality materials free for other
students please consider a donation to Runestone Academy. We ask that
you consider a \$10 donation, but if you can give more thats great, if
\$10 is too much for your budget we would be happy with whatever you can
afford as a show of support.

::: {.donateb}
[Support Runestone Academy Today](/runestone/default/donate?ad=2){.btn
.btn-info}
:::
:::
:::

::: {#chapter-assessment .section}
[16.9. ]{.section-number}Chapter Assessment[¶](#chapter-assessment "Permalink to this heading"){.headerlink}
============================================================================================================

::: {.runestone .explainer .ac_section}
::: {#ac18_7_1 component="activecode" question_label="16.9.1"}
::: {#ac18_7_1_question .ac_question}
Sort the following string alphabetically, **from z to a**, and assign it
to the variable `sorted_letters`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_2 component="activecode" question_label="16.9.2"}
::: {#ac18_7_2_question .ac_question}
Sort the list below, `animals`{.docutils .literal .notranslate}, into
alphabetical order, a-z. Save the new list as `animals_sorted`{.docutils
.literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#assess_ac18_7_2a component="activecode" question_label="16.9.3"}
::: {#assess_ac18_7_2a_question .ac_question}
Write code to rearrange the strings in the list `winners`{.docutils
.literal .notranslate} so that they are in alphabetical order by first
name from A to Z.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#assess_ac18_7_2b component="activecode" question_label="16.9.4"}
::: {#assess_ac18_7_2b_question .ac_question}
Write code to switch the order of the `winners`{.docutils .literal
.notranslate} list so that it is now Z to A, by first name. Assign this
list to the variable `z_winners`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#assess_ac18_7_2c component="activecode" question_label="16.9.5"}
::: {#assess_ac18_7_2c_question .ac_question}
Write code to switch the order of the `winners`{.docutils .literal
.notranslate} list so that it is now A to Z by *last name*. Assign this
list to the variable `z_winners`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_3 component="activecode" question_label="16.9.6"}
::: {#ac18_7_3_question .ac_question}
The dictionary, `medals`{.docutils .literal .notranslate}, shows the
medal count for six countries during the Rio Olympics. Sort the country
names so they appear alphabetically. Save this list to the variable
`alphabetical`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_4 component="activecode" question_label="16.9.7"}
::: {#ac18_7_4_question .ac_question}
Given the same dictionary, `medals`{.docutils .literal .notranslate},
now sort by the medal count. Save the three countries with the highest
medal count to the list, `top_three`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_5 component="activecode" question_label="16.9.8"}
::: {#ac18_7_5_question .ac_question}
We have provided the dictionary `groceries`{.docutils .literal
.notranslate}. You should return a list of its keys, but they should be
sorted by their values, from highest to lowest. Save the new list as
`most_needed`{.docutils .literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_6 component="activecode" question_label="16.9.9"}
::: {#ac18_7_6_question .ac_question}
Create a function called `last_four`{.docutils .literal .notranslate}
that takes in a single ID number and returns the last four digits. For
example, the number 17573005 should return 3005. Then, use the resulting
function to sort the list of ids stored in the variable, `ids`{.docutils
.literal .notranslate}, from lowest to highest. Save this sorted list in
the variable, `sorted_ids`{.docutils .literal .notranslate}. Hint:
Remember that only strings can be indexed, so conversions may be needed.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_7 component="activecode" question_label="16.9.10"}
::: {#ac18_7_7_question .ac_question}
Sort the list `ids`{.docutils .literal .notranslate} by the last four
digits of each id. Do this using lambda and not using a defined
function. Save this sorted list in the variable `sorted_id`{.docutils
.literal .notranslate}.
:::
:::
:::

::: {.runestone .explainer .ac_section}
::: {#ac18_7_8 component="activecode" question_label="16.9.11"}
::: {#ac18_7_8_question .ac_question}
Sort the following list by each element's second letter a to z. Do so by
using lambda. Assign the resulting value to the variable
`lambda_sort`{.docutils .literal .notranslate}.
:::
:::
:::
:::

::: {style="width: 100%"}
::: {ea-publisher="runestoneacademy" ea-type="image" style="display: flex; justify-content: center"}
:::
:::

::: {#scprogresscontainer}
You have attempted []{#scprogresstotal} of []{#scprogressposs}
activities on this page

::: {#subchapterprogress aria-label="Page progress"}
:::
:::

-   [[](Exercises.html)]{#relations-prev}
-   [[](../NestedData/toctree.html)]{#relations-next}
:::

::: {.container}
[]{#numuserspan}[]{.loggedinuser} \| [Back to top](#)

© Copyright 2017 bradleymiller. Created using
[Runestone](http://runestoneinteractive.org/) 7.2.10.
:::
