I am new to Python but have C/C++ background. I am trying to modify a 2D list (list of lists) elements that satisfy a condition. All I could come up with is the following solution:
tsdata = [[random.random() for x in range(5)] for y in range(5)]
def check(tsdata):
for i in range(len(tsdata)):
for j in range(len(tsdata[i])):
if (tsdata[i][j] < min_value) or (tsdata[i][j]> max_value):
tsdata[i][j] = 0
check(tsdata)
I am sure there is a better solution which is actually suitable for Python but can't think of anything else that actually works.
EDIT: Actually, the list tsdata is a function argument and I am trying to modify it so some of your answers do not work. I have edited the code so this is clear.