More efficient code, but slower program

Cecil Westerhof Cecil at decebal.nl
Wed Jul 27 11:48:47 EDT 2022


ram at zedat.fu-berlin.de (Stefan Ram) writes:

> Cecil Westerhof <Cecil at decebal.nl> writes:
>>values = [*range(100)]
>
>   In many cases, any iterable is just fine and a list is not
>   required, just as peudo-random numbers often are just fine and
>   real-world entropy is not required.

In this case both are. I must select (several times) a random element
from the list. So I need the list.
I also want the randomness to be as good as possible to make the
'simulation' as good as possible.


>   Usually one wants to write code for readability, and thinking
>   too much about runtime efficiency optimizations is in vain,
>   because one might get different results with a different
>   version of Python or on a different machine.

That is why I went for the less efficient code. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the Python-list mailing list