Control flow dictionaries

Hi friends, I am taking the 12 hour course of Python for Data Science of FreeCodeCamp in Youtube (Python for Data Science - Course for Beginners (Learn Python, Pandas, NumPy, Matplotlib) - YouTube) and I have a doubt:

I have the next syntaxis of code:

Sin título

Which gives this result:

apple 44
cherry game

And what happens is that I don’t understand what the code refers to “for x in D”. I understand that D refers to the dictionary, but what does “for x” refer to? What is x in that dictionary? I tried to change “for x” to “for z” and it gives me the following result:

cherry game
cherry game

So what do those variables refer to in that dictionary?

Also why the professor types print(x, D) instead of just print(x)?

Thanks.

Thanks Randel,

This is the code with “for z”:

Sin título 3

No, that’s the only code I have. It’s a new notebook in Jupyter.

Also, I would like to ask you why do the professor types Sin título 2 instead of just print(x).

Thanks.

This is a full screenshot of the notebook:

Randel, thanks for your help.

I have another question.

In this code, what is the value of “i” and “s”. I didn’t define them before, so what are they?

Sin título

Thanks.

So the value of S is zero, but what is the value of i after for in range is coded? What is the range there? Between which numbers?

Thanks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.