How to know the time complexity of Python built-in Function all()
?
I have tried these ways but found no answer.
all()
. This is the only file about all()
I found. enter image description hereDefinitionally O(n)
. It has to check the truthiness of all the values provided until it finds a falsy value. It short-circuits (if it finds a single falsy value, it stops immediately and returns False
without checking the rest of the input), so in many cases it won't do all the work, but if the input is in fact all truthy, it must, by definition, check all of them, doing O(n)
work. Big-O doesn't care about the possibility of short-circuiting.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.