This is my first question here. I just started coding in Python, and trying to finish an assignment for my study in Python (it is actually supposed to be made in STATA but I want to learn Python).
So I want to do the following (note that the final_list consists of 15000 rows, this is just a small example):
final_list = [[2.0, 1.0, 5.0, 11.0, 50612.0, 0.38875884563387036, 0.5924978852272034, 8.400468826293945, 516.0, 0.0, 0.0, 0.0, 2003.0], [2.0, 1.0, 5.0, 11.0, 50612.0, 0.38875884563387036, 0.5924978852272034, 8.400468826293945, 517.0, 0.0, 0.0, 0.0, 2003.0], [2.0, 1.0, 5.0, 11.0, 50612.0, 0.38875884563387036, 0.5924978852272034, 8.400468826293945, 518.0, 0.0, 0.0, 0.0, 2003.0]
to
treshold = [11.0, 11.0, 11.0]
Now what I've tried is this:
treshold = []
for sublist in final_list:
treshold_lst = sublist[3]
treshold.append(treshold_lst)
print(treshold)
I receive the following error:
IndexError: list index out of range
Does anyone see what I'm doing wrong?
final_listlooks like that?final_listyou've posted now is invalid. The problem obviously lies with that list, not with the logic you've posted.