[issue18844] allow weights in random.choice

2016-04-07 Thread Steven Basart
Steven Basart added the comment: Left in a line of code that was supposed to be removed. Fixed. -- Added file: http://bugs.python.org/file42393/weighted_choice_v5.patch ___ Python tracker <http://bugs.python.org/issue18

[issue18844] allow weights in random.choice

2016-04-07 Thread Steven Basart
Changes by Steven Basart : Removed file: http://bugs.python.org/file42392/weighted_choice_v5.patch ___ Python tracker <http://bugs.python.org/issue18844> ___ ___ Pytho

[issue18844] allow weights in random.choice

2016-04-07 Thread Steven Basart
Steven Basart added the comment: Re-implemented with suggested improvements taken into account. Thanks @mark.dickinson and @pitrou for the suggestions. I also removed the redundant "fast path" portion for this code since it doesn't deal with generators anyways. Let me

[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart
Steven Basart added the comment: I reuploaded the file. The spacing on the if amount < 1 was off. Hopefully its fixed now. -- Added file: http://bugs.python.org/file42386/weighted_choice_v4.patch ___ Python tracker <http://bugs.pyth

[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart
Changes by Steven Basart : Removed file: http://bugs.python.org/file42385/weighted_choice_v4.patch ___ Python tracker <http://bugs.python.org/issue18844> ___ ___ Pytho

[issue18844] allow weights in random.choice

2016-04-06 Thread Steven Basart
Steven Basart added the comment: Okay so I added a few lines of code. One to make it return a single number if amount == 1 and the other to check that the amount > 1. The main difference I've noticed between this implementation and previous versions compared to say R is that i

[issue18844] allow weights in random.choice

2016-03-30 Thread Steven Basart
Steven Basart added the comment: Hey serhiy.storchaka I can edit the code to output just one value if called with simply a list and then return a list of values if called with the optional amount parameter. My code also needs to check that amount >= 1. My code was mostly just to rest

[issue18844] allow weights in random.choice

2016-03-30 Thread Steven Basart
Steven Basart added the comment: Hello rhettinger. I filled out the form thanks for letting me know about it. Is there anything else I have to do? Hey serhiy.storchaka There were several things "wrong" with the previous implementation in my opinion. 1st they tried to add too mu

[issue18844] allow weights in random.choice

2016-03-29 Thread Steven Basart
Steven Basart added the comment: The entire function of weighted choice. I removed the generator and replaced it by adding an optional argument to specify an amount by which you want to call this function. -- Added file: http://bugs.python.org/file42323/weighted_choice_v3.patch

[issue18844] allow weights in random.choice

2016-03-29 Thread Steven Basart
Steven Basart added the comment: Reopen this idea but removing the generator from weighted choice. -- nosy: +progressive-o Added file: http://bugs.python.org/file42322/weighted_choice_v3.diff ___ Python tracker <http://bugs.python.org/issue18