HopsonCommunity / TextAdventure

A text adventure made by a couple of members on the Hopson Community Server.
MIT License
5 stars 9 forks source link

Use `all` build-in function #14

Closed Hazurl closed 6 years ago

Jackojc commented 6 years ago

ah yes, very nice

Jackojc commented 6 years ago

just to note, this may potentially be slower due to having to evaluate all the expressions in the list, but its a good use of python features and its looks great!

iCiaran commented 6 years ago

I believe if you remove the [] it will be evaluated lazily. (and therefore the same speed as previously).

Did a couple of tests, seems to be correct

>>> import timeit
>>> timeit.timeit('any([x == 52 for x in l])',setup='l = [x for x in range(1000)]', number=10000)
0.4704603556645566
>>> timeit.timeit('any(x == 52 for x in l)',setup='l = [x for x in range(1000)]', number=10000)
0.04013646315647179

Changed in #15