Python Forum
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop the difference
#2
Your code is definitely better, with the recommendation to use more descriptive names like genres = ... and for genre in genres: instead of i. We even have special thread in Tutorials - Never use "for i in range(len(sequence)):"

I looked at the article in your link - note that it's just an example, i.e. they show the more pythonic way first and they also show what you can do too using index. In other words I would say it's just for educational purposes
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
for loop the difference - by 3Pinter - Jan-10-2019, 01:59 PM
RE: for loop the difference - by buran - Jan-10-2019, 02:11 PM
RE: for loop the difference - by 3Pinter - Jan-10-2019, 02:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between word: and word[:] in for loop zowhair 2 3,688 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020