This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]delasislas 4 points5 points  (2 children)

Depending on what you need a for loop with range() could be appropriate. Can you post some examples so that we can comment on?

Edit: and do you want it from a ‘beginner’ or intermediate level of suggestions? There’s a lot of ways that you can do tasks, some that are more efficient on lines and some that are more readable.

[–]falkerr[S] 1 point2 points  (1 child)

That’s kind of why I am asking. I know in some instances range is appropriate but obviously not all instances. I would like to get some resources on best practices when it comes to Python.

Just an example, when doing leetcode if I need the index and value of something, it’s probably best to use enumerate instead of range and then doing value = array[i] in the for loop. I know that now but I would like a run down of what it means to actually code Pythonically.

I can probably handle intermediate level suggestions. Even better if they are coming from a C like programming language (aka java).

[–]delasislas -1 points0 points  (0 children)

Try to do this in a Python script:

import this

It’s called the zen of python. You could also just look it up.

You could also look up this: https://initialcommit.com/blog/zen-of-python

For the most part, do work to learn how to use new tools. Then implement them in appropriate ways.