6. What are the names of the winners?

6.1. Using another list

  • We can use two lists to find out.

  • The names and scores lists to save the names and scores obtained by the participants respectively.

System Message: ERROR/3 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP37/TWP37_6_en.rst, line 17)

Duplicate ID – see lectures/TWP37/TWP37_6, line 21

..  datafile:: surf4.txt
    :hide:

    Johny 8.65
    Juan 9.12
    Joseph 8.45
    Stacey 7.81
    Aideen 8.05
    Zack 7.21
    Aaron 8.31

6.2. But these data are incorrect!

  • There must be a problem because Zack is really bad!

  • What happened?

  • By sorting the names list in decreasing order, the character 'Z' ends up being the first.

  • The correspondence between scores and the names of the participants is lost.

  • Another data structure is needed to avoid losing the correspondence.

6.3. We need to join the lists

6.4. Using and sorting a dictionary

  • Using a dictionary and seeing all its elements iteratively.

Activity: CodeLens 6.4.1 (cl_l37_6_en)

  • Using a dictionary for the championship.

You have attempted of activities on this page