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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -