Prison Break total fail on nested iteration- want to understand the naming conventions

hey folks-
first week in learning python- 2nd week learning any type of code at all. total newbie for all purposes here.

working through the prison break project, and wound up with a total fail. spent probably and hour because i was following the instructions too closely without just letting myself write the code. i understood the process the code should be running, just wasnt sure how to express it. sticking to the names/variables provided kept me from figuring it out on my own.

link to instructions

so for some reason the thing we’re looking at in attempts/year list of list is referred to as ‘ya’ here in the ‘for’ iteration line. that was totally nonsensical to me, and made me think i didnt understand the problem. once i gave up and searched for answers i saw other folks just used their own naming systems and then i instantly got it. the instructions seemd badly arranged, and once moved around it all worked.

so my question is this- who/what/how is this ‘thing’ in an iteration line named? should it refer to something in particular? is it usually derived from some other variable/list/etc? what’s the ‘best’ way to understand how to apply names for the sake of clarity and logic? this is all new to me so any explanation of common or typical naming conventions would be appreciated.

2 Likes

Hi @antlavia
First of all welcome to both the dataquest community and the data science community.

The best way to name the iterator in any for loop is using the singular name, if possible of the thing that you are going to loop through, so for example you have a list named “Numbers” the iterator could be named “Number” so you’d get For Number in Numbers, and it’s way more clear.

Obviously sometimes it’s going to be hard to name an iterator as sometimes you are not going to have clear and friendly variable names but if you write the code from the beggining then just remember to use good name for your variables and iterators.

Check the PEP8 guide which is the guide to write better and easy to read code in python

Good luck in your journey

3 Likes

Hello @antlavia,

That’s valid feedback.

My suggestion is to share your feedback with the Content & Product teams of Dataquest. Just click the ? button in the upper-right corner of any screen of the Dataquest learning platform, select Share Feedback, fill in the form, and send it.

On naming, aside from following the PEP8 guideline shared by @alegiraldo666, it’s best to emphasize clarity over brevity especially if you’re starting out. The downside is clear variable names can be very long at times; but it shouldn’t be that much of a problem considering that we’re living in an age of Integrated Development Environments (IDE) with very good autocomplete feature.

One thing to also note if you’re working in a team or contributing to an open-source project, you may not have the liberty in deciding how a variable should be named. What’s ‘best’ will depend on the style guide of each project and each guide can differ a lot between one project to another.

Hopefully that helps.

1 Like

Totally true, in at least two projects that I worked we discussed how to name each variable, we had liberty to name iterators though, but the only recommendation is that we choose a clear name and explain it in the documentation.

I’m agree that there is a need to change the name of that iterator, @Elena_Kosourova can we do something about it?

2 Likes

That’s a good point, that is the freedom you get can differ between projects. Maybe I’ll change my suggestion to “may not have the liberty” instead of “don’t”.

1 Like

Hi @antlavia, @alegiraldo666, @wanzulfikri,

Your suggestion about renaming that iterator seems very valid to me. Indeed, I totally agree here with the suggestion from Wan about sending feedback about it to the Content & Product teams of DQ:

My suggestion is to share your feedback with the Content & Product teams of Dataquest. Just click the ? button in the upper-right corner of any screen of the Dataquest learning platform, select Share Feedback, fill in the form, and send it.

Could you guys please do so all three of you? Because it takes only a couple of minutes to send it, and the more people provide the same feedback the higher is the priority of implementing it.

Many thanks! :pray:

1 Like

thank you @alegiraldo666 and @wanzulfikri . i’ll look up the pep8 stuff and read through it. submitted a suggestion as well, maybe a sidebar in the earlier lessons on naming, or pop up window/mouseover on the y and the ya with explanations of naming and what they represent would be possible aids for newbies.

2 Likes

Will do, @Elena_Kosourova. Here’s hoping that it’ll help future learners who encounter the same issue.

1 Like