I am writing a program that calculates the minimum and maximum of 10 numbers from a list (data1). I am receiving a “TypeError: ‘float’ object is not iterable” for the following lines:
temp_min10=min(data1[x-z][3])
temp_max10=max(data1[x-z][2])
Full program:
x=int(0)
for line in data1:
if x>=9:
min10=0
max10=0
for z in range(0,10):
temp_min10 = temp_max10 = 0
temp_min10=min(data1[x-z][3])
if temp_min10<min10:
min10=temp_min10
temp_max10=max(data1[x-z][2])
if temp_max10>max10:
max10=temp_max10
d_chan.append([max10,min10])
else:
d_chan.append([0,0])
x+=1
Thanks for any help!
The possible args for
minandmaxare either one iterable or 2 or more scalars. Docs here. You have given it one arg which is not an iterable; it’s a float.Aside: (1) Your indentation as displayed is patently incorrect. You need to (a) avoid tabs in your source file (b) ensure that your indentation is logically correct. (2) Your code is iterating
for line in data1:but never mentionslineagain; looks like you need to check carefully what you are doing withx; it’s not obvious.Update after reading your code again:
The following code will probably do what you want.