Solved

Building a dict index — memory vs speed?

AmeliaRunsOP

Doesn't duplicating the data in a dict use double memory?

5

Comments 4

Join the discussion

Already have an account? Log in

  1. EmmaCodes Solutionreplies: 2

    The dict doesn't copy the records — it stores references to the same dict objects. So the extra memory is just the keys and pointers. In exchange, every lookup is instant instead of scanning the list.

    8
    1. AmeliaRunsOPreplies: 1

      References, not copies. Same lesson as backup = crew, but useful this time 😄

      0
      1. LiamByte

        Comprehensions come later in the course, but good to see it.

        3
    2. ZosiaN

      Dict comprehension version: {r["id"]: r for r in cargo}. One line.

      5