Skip to content

Improved for loops to Python style#1

Open
jonfitt wants to merge 1 commit intoWireframe-Magazine:mainfrom
jonfitt:improve_for_loops
Open

Improved for loops to Python style#1
jonfitt wants to merge 1 commit intoWireframe-Magazine:mainfrom
jonfitt:improve_for_loops

Conversation

@jonfitt
Copy link

@jonfitt jonfitt commented Jul 8, 2022

I see you're coming from a C based language to Python like I did :)
Python has a cool way of iterating through lists that doesn't require making a new index list and then going through by number you can just do:

for item in items:
   print(item)

If you need the index number you can also use enumerate:

for index, item in enumerate(items):
     print(f"item number {index} is {item})

That way in your functions instead of referring to bullets[b] you can just say bullet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments