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
Post a Comment