python - Pythonic way to modify list element if condition is met -


i have this:

mylistoflists = [["descra",true,3],["descrb",true,5],["descrb",true,65],..] 

for each element in list need set mylistoflists[element][1] false if mylistoflists[element][2] <= 30.

mylistoflists should become:

[["descra",false,3],["descrb",false,5],["descrb",true,65],..] 

what best approach in python that?

there lots of ways it, depending on mean "best approach in python". 1 of them:

for in mylistoflists:     if i[2] <= 30:         i[1] = false 

since "best" mean: fast, memory efficient, readable etc can check method suits needs.

for example check speed can use timeit , compare various solutions.


what "best" should not mean, "unnecessarily complex".


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -