python - How to add number to list in for loop? -
here, h list of integers.
per condition in for loop, want add/subtract numbers list.
for in range(len(h)): if h[i] > 43: d.append(int(int(h[i]) - int(33))) m.append(ovf(h[i])) #print h elif (h[i]) < -43: d.append(h[i] + 33) m.append(ovf(h[i])) else: d.append(h) i getting error @ d.append(int(int(h[i]) - int(33))).
please help, new python. error i'm receiving is:
typeerror: int() argument must string or number, not 'list'.
you wrote h[i] list , error tells int() doesn't work kind of input, guess error occurs when call int(h[i]).
can verify with
>>> int([1., 2., 3.]) traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: int() argument must string, bytes-like object or number, not 'list' >>> list(int(k) k in [1., 2., 3.]) [1, 2, 3] i guess expecting output [1, 2, 3] call of int([1., 2., 3.]) in above example you're new python. think want instead is
d.append([int(h)-33 h in h[i]]) example:
>>> d = [] >>> d.append([int(h)-33 h in [1., 2., 3.]]) >>> d [[-32, -31, -30]]
Comments
Post a Comment