I read from range(len(list)) or enumerate(list)? that using range(len(s))
is not very good way to write Python. How one can write for loops in alternative way if we do not need to loop len(s)
times but for example len(s)//3
times or len(s)-5
times? Is it possible to convert those loops to use enumerate
?
For example, I had a project where I had a list of 3n elements 's[0], s[1],...,s[3n-1]' and I needed to print them in a nx3 table. I wrote the code something like
for i in range(len(s)//3):
row = str(s[3*i]) + " " + str(s[3*i+1]) + " " + str(s[3*i+2])
print(row)