Basically, I am wondering what is the most efficient method to find the elements of a python list with a value of greater than, say, n.
I believe, the easiest, yet not so efficient, way is as below,
for i in range(len(theList)):
if theList[i] > n:
subList.append(theList[i])
Moreover, we have the single line for
as below,
(subList for subList in theList if sublist > n)
(Please correct me if there is anything wrong with the above syntax)
Finally, we can use filter()
function, which is not pleasant to use, at least for me.
The above methods were all the ways that I know. If you know any better method please tell me. Otherwise, please explain which one is the best, in the sense of efficiency and run-time.