Solved Building a dict index — memory vs speed? AMAmeliaRunsOP 2 Oct, 08:52 Doesn't duplicating the data in a dict use double memory?
EMEmmaCodes2 Oct, 17:50 Solutionreplies: 2The 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.
AMAmeliaRunsOP2 Oct, 18:10replies: 1References, not copies. Same lesson as backup = crew, but useful this time 😄
Comments 4
Join the discussion CommentAlready have an account? Log in
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.
References, not copies. Same lesson as backup = crew, but useful this time 😄
Comprehensions come later in the course, but good to see it.
Dict comprehension version:
{r["id"]: r for r in cargo}. One line.