Jun-16-2019, 08:53 PM
(Jun-16-2019, 05:52 PM)pooyan89 Wrote: I am not a very good programmer and had not a very good teacher! but at all cost I am trying to learn the base of programming... that is because I use this. It seems much more easier for me to write for example:
for i in range(len(a))
But you say it is a bad pattern for looping through a list ?
One of the reasons why
for i in range(len(a))
is considered antipattern is that integer is usually used to access list elements by index. You don't need to do it in Python, as noisefloor pointed out you can iterate directly over list element without need to mess with access by indices. However, if you need integer then you should use enumerate.If you want to learn fundamentals then you should not go for 'more easier for me to write' but 'what are the best practices' and 'why are they considered best practices'
One easy to understand and well presented material is Ned Batchelder Loop Like a Native
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.