Skip to content

Improved for loops to Python style #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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