DjangoGirls / tutorial

This is a tutorial we are using for Django Girls workshops
http://tutorial.djangogirls.org/
Other
1.53k stars 1.86k forks source link

Dictionary tutorial can be a bit misleading #1745

Closed knyghty closed 2 years ago

knyghty commented 2 years ago

Issue description

This came up in a workshop today.

In the dictionary tutorial, a dict is created with three keys:

>>> participant = {'name': 'Ola', 'country': 'Poland', 'favorite_numbers': [7, 42, 92]}

Later, there is a section showing how to add a key:

>>> participant['favorite_language'] = 'Python'

And then showing how you can get the length:

>>> len(participant)
3

The first command is preceded by "try writing the following command". The second doesn't have an explicit instruction "you can". And the third starts with "go ahead and type this command". So the result of len(participant) is correct if the user didn't type the second example (it should be 4). This caused a bit of confusion. I think this could be reworded a bit so that the second part is an instruction and then the return value of len(participant) can be 4.

Language

English but I didn't check others.

magul commented 2 years ago

It looks like a bug introduced in #1743.

CC: @das-g @BiplawSingh

BiplawSingh commented 2 years ago

Thanks @knyghty @magul for pointing it out I think explaining the len() function before adding the new key-value pair would be a better idea

das-g commented 2 years ago

Thank you @knyghty for pointing this out. :heart:

Thank you @BiplawSingh for the suggested fix. In my opinion, the reordering suggested in 7de4db4968197a9a7cb4a8837cddd2d286e4a30e does indeed make sense. As pull request BiplawSingh/tutorial#1 had the master branch of your own fork as its target, which doesn't have much effect, I've opened a new pull request #1747 with your commit (and with a small source-only modification by me.)