Python-list Digest, Vol 176, Issue 16

Paul Moore p.f.moore at gmail.com
Mon May 14 18:43:03 EDT 2018


On 14 May 2018 at 20:02, Paul <tallpaul at gmail.com> wrote:
> 1) I understand the added cost of verifying the sequence.  However, this
> appears to be a one-time cost.  E.G., if I submit this,
>
> random.choices(lm,cum_weights=[25,26,36,46,136],k=400
>
> then the code will do an O(n log n) operation 400 times.
>
> If verification was added, then the the code would do an O(n log n)
> operation 400 times, plus an O(n) operation done *one* time.   So, I'm not
> sure that this would be a significant efficiency hit (except in rare cases).

That's a good point. But as I don't have any need myself for
random.choices with a significant population size (the only case where
this matters) I'll leave it to those who do use the functionality to
decide on that point.

Regards,
Paul



More information about the Python-list mailing list