I understand that loops are a bad idea in python and I should avoid them.
Well, I have several of those I want to avoid.
I have a list of stuff named lipid:
class bead: x = 0 y = 0 z = 0 LID = 0 t = 0 class lipid: h = bead() b = bead() t = bead() LID = 0 and I am doing the following (code below):
- initializing a 2d array of
hs going over all the lipids and - determine if they are counted as
Uor down - adding value to the appropriate
h
How can I avoid, at least, the first loop?
1:
class h: cU = 0 cD = 0 hU = 0 hD = 0 h = 0 for i in range(0,8): hs.append([]) for j in range(0,8): index = (i,j) hn = h() hs[i].append(hn) 2 and 3:
for LID in lipids: l = lipids[LID] up = l.h.z > l.t.z X = (int)(l.b.x*8/L) Y = (int)(l.b.y*8/L) Z = (l.b.z)*0.5 if up: hs[X][Y].hU += Z hs[X][Y].cU += 1 else: hs[X][Y].hD += Z hs[X][Y].cD += 1
I understand that loops are a bad idea in python and I should avoid them.-- wat? Where did you get that idea? Iteration is encouraged over recursion. Now, quite a few simpleforloops can be replaced with syntactic sugar (a ways of doing the same thing with nicer source code). But those are just a better way to write loops.