Re: [Python-ideas] shuffled as a way to shuffle an iterable

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 9:36 AM, Xavier Combelle wrote: > and eventually this one work in all case of iterable > > def shuffled3(iterable): > result = list(iterable) > random.shuffle(result) > return result > This is the one obvious way to do this. Not all iterables can logically be sh

[Python-ideas] shuffled as a way to shuffle an iterable

2016-09-08 Thread Xavier Combelle
When thinking about the shuffled thread, it occurred to me that it was quite easy to pass an iterable and expect the iterable to be shuffled. but two mentioned implementation are close to success but fail by not taking this use case in account: def shuffled1(iterable): result = iterable[:]

Re: [Python-ideas] Shuffled

2016-09-08 Thread Arek Bulski
Hey, I just did put my thoughts on the discussion floor. Dont yell at me for it not being the most interesting idea ever. There were few interesting responses after all. Lets move on. pozdrawiam, Arkadiusz Bulski ___ Python-ideas mailing list Python-id

Re: [Python-ideas] Shuffled

2016-09-08 Thread David Mertz
I also can't really get from "Arek has a need for this one line definition" to "it should be in the standard library". Sure, 'shuffled()' is a more obvious spelling than the slightly odd lambda. But I've yet to see the reason that alias can't just be defined at the top of the test suite. On Sep 8,

Re: [Python-ideas] Shuffled

2016-09-08 Thread Tim Peters
[Arek Bulski ] > I dont randomize test order. People should stop assuming that they know > better. They should, but, to be fair, you've left them little choice because you've been so telegraphic about why you think this is a compelling idea. Others are trying to fill in the blanks, and can only g

Re: [Python-ideas] Shuffled

2016-09-08 Thread Paul Moore
On 8 September 2016 at 16:59, Arek Bulski wrote: >> You've probably spent way more time debating shuffled here than you would >> have needed to add a shuffled function to your test file. > > Another presupposition. I did add it to my utility. I am proposing to add > this to the std library so that

Re: [Python-ideas] Shuffled

2016-09-08 Thread Arek Bulski
> You've probably spent way more time debating shuffled here than you would have needed to add a shuffled function to your test file. Another presupposition. I did add it to my utility. I am proposing to add this to the std library so that others dont have to. pozdrawiam, Arkadiusz Bulski ​​ ___

Re: [Python-ideas] Shuffled

2016-09-08 Thread Steven D'Aprano
This thread is just going around and around in circles, so I will make one final response and then I'm going to bow out. On Thu, Sep 08, 2016 at 11:34:57AM +0200, Arek Bulski wrote: > Needs to be shuffled(). > > https://github.com/construct/construct/blob/master/tests/test_all.py > See? No way

Re: [Python-ideas] Shuffled

2016-09-08 Thread Alexander Belopolsky
> On Sep 8, 2016, at 5:34 AM, Arek Bulski wrote: > > > So, why can't you call random.shuffle(all_tests) if you want to run your > > tests in random order? > > I dont randomize test order. People should stop assuming that they know > better. That's the best I could do given the minimal explan

Re: [Python-ideas] Shuffled

2016-09-08 Thread Paul Moore
On 8 September 2016 at 10:34, Arek Bulski wrote: > That wont work because I would have to type the expression that is used as > argument twice in a test. I need shuffled. Enough said. You've probably spent way more time debating shuffled here than you would have needed to add a shuffled function

Re: [Python-ideas] Shuffled

2016-09-08 Thread Danilo J. S. Bellini
> > That wont work because I would have to type the expression that is used as > argument twice in a test. (lambda data: random.sample(data, len(data)))(container) That lambda is actually your "shuffled"... 2016-09-08 6:34 GMT-03:00 Arek Bulski : > > So, why can't you call random.shuffle(all_te

Re: [Python-ideas] Shuffled

2016-09-08 Thread Arek Bulski
> So, why can't you call random.shuffle(all_tests) if you want to run your tests in random order? I dont randomize test order. People should stop assuming that they know better. I need to randomize some arguments for one particular test and I cannot call shuffle between tests. Its a continous list

Re: [Python-ideas] Shuffled

2016-09-08 Thread Nick Coghlan
On 8 September 2016 at 15:05, Danilo J. S. Bellini wrote: >> 1. The cognitive leap between shuffling and sampling isn't small > > I don't think so, actually the Fisher-Yates shuffle algorithm algorithm is > an iterative sampling algorithm: > https://gist.github.com/danilobellini/6384872 I'm not t

Re: [Python-ideas] Shuffled

2016-09-07 Thread Danilo J. S. Bellini
> > 1. The cognitive leap between shuffling and sampling isn't small > I don't think so, actually the Fisher-Yates shuffle algorithm algorithm is an iterative sampling algorithm: https://gist.github.com/danilo bellini/6384872 > 2. "shuffled" would be a more logical name for an out-of-place shuffl

Re: [Python-ideas] Shuffled

2016-09-07 Thread Nick Coghlan
On 8 September 2016 at 13:33, Danilo J. S. Bellini wrote: > Nice to know about random.sample! =) > > I think what OP said can then be reduced to having the default k in > random.sample to be the iterable size. The existance of random.sample is a > very strong argument against "shuffled", and the o

Re: [Python-ideas] Shuffled

2016-09-07 Thread Danilo J. S. Bellini
Nice to know about random.sample! =) I think what OP said can then be reduced to having the default k in random.sample to be the iterable size. The existance of random.sample is a very strong argument against "shuffled", and the only "feature" shuffled would have that random.sample doesn't have is

Re: [Python-ideas] Shuffled

2016-09-07 Thread Nick Coghlan
On 8 September 2016 at 13:23, Nick Coghlan wrote: > Beyond that practical benefit, if you want > random-sampling-with-replacement, then "map(random.choice, container)" Oops, that was supposed to be "map(random.choice, itertools.repeat(container))". Cheers, Nick. -- Nick Coghlan | ncogh...

Re: [Python-ideas] Shuffled

2016-09-07 Thread Nick Coghlan
On 8 September 2016 at 12:47, Danilo J. S. Bellini wrote: > Though I agree with the argument that inexperienced developers are [usually] > worse, that's not the case here, unless anyone here is really trying to say > the ones arguing for or against "shuffled" are inexperienced. These ad > hominem

Re: [Python-ideas] Shuffled

2016-09-07 Thread Steven D'Aprano
On Wed, Sep 07, 2016 at 11:47:49PM -0300, Danilo J. S. Bellini wrote: > Though I agree with the argument that inexperienced developers are > [usually] worse, that's not the case here, unless anyone here is really > trying to say the ones arguing for or against "shuffled" are inexperienced. > These

Re: [Python-ideas] Shuffled

2016-09-07 Thread Nick Coghlan
On 8 September 2016 at 12:00, Steven D'Aprano wrote: > On Wed, Sep 07, 2016 at 11:43:59PM +0200, Sven R. Kunze wrote: > >> BUT experienced devs also need to recognize and respect the fact that >> younger/unexperienced developers are just better in detecting >> inconsistencies and bloody work-aroun

Re: [Python-ideas] Shuffled

2016-09-07 Thread Danilo J. S. Bellini
Though I agree with the argument that inexperienced developers are [usually] worse, that's not the case here, unless anyone here is really trying to say the ones arguing for or against "shuffled" are inexperienced. These ad hominem won't bring us anywhere. No one seem to be arguing if "shuffled" i

Re: [Python-ideas] Shuffled

2016-09-07 Thread Steven D'Aprano
On Thu, Sep 08, 2016 at 12:22:28AM +0200, Sven R. Kunze wrote: > About the confusion of returning None. It's not confusing in the sense > of "o my god, I did it wrong, I need to learn it", but more, like "I > used shuffle, BECAUSE it's the only one I could find in a hurry" Then don't be in such

Re: [Python-ideas] Shuffled

2016-09-07 Thread Steven D'Aprano
On Wed, Sep 07, 2016 at 11:43:59PM +0200, Sven R. Kunze wrote: > BUT experienced devs also need to recognize and respect the fact that > younger/unexperienced developers are just better in detecting > inconsistencies and bloody work-arounds. That is not a fact. It is the opposite of a fact -- i

Re: [Python-ideas] Shuffled

2016-09-07 Thread Alexander Belopolsky
On Wed, Sep 7, 2016 at 9:12 PM, Alexander Belopolsky < alexander.belopol...@gmail.com> wrote: > On Wed, Sep 7, 2016 at 8:14 PM, Arek Bulski wrote: > > > > If you want to see the declarative tests, here it is. > > https://github.com/construct/construct/blob/master/tests/test_all.py > > > So, why c

Re: [Python-ideas] Shuffled

2016-09-07 Thread Alexander Belopolsky
On Wed, Sep 7, 2016 at 8:14 PM, Arek Bulski wrote: > > If you want to see the declarative tests, here it is. > https://github.com/construct/construct/blob/master/tests/test_all.py So, why can't you call random.shuffle(all_tests) if you want to run your tests in random order? If for some reason

Re: [Python-ideas] Shuffled

2016-09-07 Thread Arek Bulski
If you want to see the declarative tests, here it is. https://github.com/construct/construct/blob/master/tests/test_all.py pozdrawiam, Arkadiusz Bulski 2016-09-08 2:13 GMT+02:00 Arek Bulski : > See for yourself. There is a long list of declarative tests. > https://github.com/construct/construct

Re: [Python-ideas] Shuffled

2016-09-07 Thread Alexander Belopolsky
On Wed, Sep 7, 2016 at 6:56 PM, Arek Bulski wrote: > In the project I maintain (construct) there are declarative testcases that > look like a long list of (func, args, excepted output, error type) tuples. > There is no way for me to call shuffle in there. Can you explain why? Something like th

Re: [Python-ideas] Shuffled

2016-09-07 Thread Rob Cliffe
On 07/09/2016 23:41, Matt Gilson wrote: I lurk around here a lot more than I actually post Very wise. I am a tournament Bridge player, and one of the things I say to my partners is: "Bidding is very simple. When you have something to say, say it (unless it really seems too dangerous). When

Re: [Python-ideas] Shuffled

2016-09-07 Thread David Mertz
On Wed, Sep 7, 2016 at 3:10 PM, Sven R. Kunze wrote: > @David > Your idea of a PyPI package could almost work. However, in an interactive > python console, I expect as much batteries included as possible to make it > as quick as possible. And considering how simple such wrapper would be, it > alm

Re: [Python-ideas] Shuffled

2016-09-07 Thread Sven R. Kunze
On 08.09.2016 00:41, Matt Gilson wrote: I lurk around here a lot more than I actually post -- But in this case I find myself weighing in firmly on the side of "please don't add this". It'd just add noise in the documentation and __builtins__ namespace. There are millions of useful functions t

Re: [Python-ideas] Shuffled

2016-09-07 Thread Arek Bulski
Thank you all for the meta discussion. I know we sidetracked a bit but please everyone remember, this is an open discussion floor. I can present you a use case, just didnt think I even needed one. This seems so obvious to me that it should just go in without much saying. In the project I maintain

Re: [Python-ideas] Shuffled

2016-09-07 Thread Matt Gilson
I lurk around here a lot more than I actually post -- But in this case I find myself weighing in firmly on the side of "please don't add this". It'd just add noise in the documentation and __builtins__ namespace. There are millions of useful functions that *could* be added to the `list` object (or

Re: [Python-ideas] Shuffled

2016-09-07 Thread Sven R. Kunze
Maybe, there's a misunderstanding here and I hope I didn't waste too much of your and my time. Not sure where I got this from but my last status was that Arek would like to have a "shuffled" function that does exactly what you described. Maybe, that doesn't fit the reports description but his

Re: [Python-ideas] Shuffled

2016-09-07 Thread Sven R. Kunze
On 07.09.2016 02:49, Chris Kaynor wrote: I'll weigh in and say that I've had a few cases where I've wanted a shuffled function, but not many. The vast majority are interactive uses, where I want to get a sampling of data, and in those cases I'm normally just printing the output (often, by letti

Re: [Python-ideas] Shuffled

2016-09-07 Thread Tim Peters
[Sven R. Kunze ] > I am not questioning experience which everyone in a team can benefit from. > > > BUT experienced devs also need to recognize and respect the fact that > younger/unexperienced developers are just better in detecting > inconsistencies and bloody work-arounds. They simply haven't ha

Re: [Python-ideas] Shuffled

2016-09-07 Thread Sven R. Kunze
On 06.09.2016 21:29, Tim Peters wrote: In the absence of anything approaching [use-cases], it's a matter of taste, and then - yes - decades of Python development experience do - and should - outweigh a newcomer's wish list. Especially when, as appears to be the case here, those with truly exte

Re: [Python-ideas] Shuffled

2016-09-06 Thread Ethan Furman
On 09/06/2016 11:15 AM, Sven R. Kunze wrote: On 06.09.2016 18:32, Steven D'Aprano wrote: If your only argument is to continue to insist that Python should have a shuffled() function and you'll write a patch, it will go no where. First you have to convince people that the patch is needed. He

Re: [Python-ideas] Shuffled

2016-09-06 Thread Chris Kaynor
On Tue, Sep 6, 2016 at 3:04 PM, Tim Peters wrote: > But would you _use_ it? I'm still asking for use cases. > > When, e.g., I'm randomizing permutations for testing, the last thing I > want is: > > while whatever: > result = function_of_xs(shuffled(xs)) > check result and com

Re: [Python-ideas] Shuffled

2016-09-06 Thread Tim Peters
[David Mertz ] > This definitely feels like a case of "put it on PyPI." Actually, maybe > contribute to `boltons`, it feels like it might fit as a utility function > there. It's trivial to write such a function if it's truly needed - it would be easier to write it from scratch than to remember wh

Re: [Python-ideas] Shuffled

2016-09-06 Thread Tim Peters
On Tue, Sep 6, 2016 at 2:48 PM, David Mertz wrote: > On Tue, Sep 6, 2016 at 1:15 PM, Sven R. Kunze wrote: >> >> Their response: "Oh, I don't need it, let's close it." >> Arek: "But I need it." > > > This definitely feels like a case of "put it on PyPI." Actually, maybe > contribute to `boltons`,

Re: [Python-ideas] Shuffled

2016-09-06 Thread David Mertz
On Tue, Sep 6, 2016 at 1:15 PM, Sven R. Kunze wrote: > > Their response: "Oh, I don't need it, let's close it." > Arek: "But I need it." > This definitely feels like a case of "put it on PyPI." Actually, maybe contribute to `boltons`, it feels like it might fit as a utility function there. Whil

Re: [Python-ideas] Shuffled

2016-09-06 Thread Tim Peters
[Sven R. Kunze ] >>> >>> ... >>> He already convinced some people. Just not some venerable Python devs, >>> which>> doesn't necessarily mean something at all. >>> >>> Their response: "Oh, I don't need it, let's close it." >>> Arek: "But I need it." >>> >>> So, who's right now? [Tim] >> By default,

Re: [Python-ideas] Shuffled

2016-09-06 Thread Sven R. Kunze
On 06.09.2016 20:46, Bernardo Sulzbach wrote: On 09/06/2016 03:37 PM, Sven R. Kunze wrote: Besides being a silly argument, it's an interesting solution. Does it really work? I remember Microsoft utilizing a similar approach for their browser selection tool which led to a skewed probability dis

Re: [Python-ideas] Shuffled

2016-09-06 Thread Sven R. Kunze
On 06.09.2016 20:46, Tim Peters wrote: [Sven R. Kunze ] ... He already convinced some people. Just not some venerable Python devs, which doesn't necessarily mean something at all. Their response: "Oh, I don't need it, let's close it." Arek: "But I need it." So, who's right now? By default, th

Re: [Python-ideas] Shuffled

2016-09-06 Thread אלעזר
(Just to be clear, I wasn't trying to suggest this as more than an ad-hoc solution for a throwaway script. But to me, "sorted by random key" is almost as obvious as "shuffled", perhaps more so for non english speakers with little background in CS terms; the words "sorted" and "random" jumps to the

Re: [Python-ideas] Shuffled

2016-09-06 Thread Bernardo Sulzbach
On 09/06/2016 03:37 PM, Sven R. Kunze wrote: Besides being a silly argument, it's an interesting solution. Does it really work? I remember Microsoft utilizing a similar approach for their browser selection tool which led to a skewed probability distribution. Maybe, I wrong here though. Yes.

Re: [Python-ideas] Shuffled

2016-09-06 Thread Tim Peters
[Sven R. Kunze ] > ... > He already convinced some people. Just not some venerable Python devs, which > doesn't necessarily mean something at all. > > Their response: "Oh, I don't need it, let's close it." > Arek: "But I need it." > > So, who's right now? By default, the venerable Python devs ;-)

Re: [Python-ideas] Shuffled

2016-09-06 Thread Sven R. Kunze
Are you serious? The reason for "we don't need standardization" == "there is a solution, long, and with a lot of special characters". Holy c***. I remember Python being the least verbose language on the planet. I suspect this argument didn't lead to status quo. It's like saying, we don't need v

Re: [Python-ideas] Shuffled

2016-09-06 Thread אלעזר
Naive shuffled() can be emulated using a single expression: sorted(lst, key=lambda _: random()) So there's even less incentive for standardization. ~Elazar ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinf

Re: [Python-ideas] Shuffled

2016-09-06 Thread Chris Angelico
On Wed, Sep 7, 2016 at 4:15 AM, Sven R. Kunze wrote: > It's community project after all. What's that mean, exactly? That the community gets to vote on what goes into Python? Because we don't. ChrisA ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Shuffled

2016-09-06 Thread Sven R. Kunze
Hi Steven, On 06.09.2016 18:32, Steven D'Aprano wrote: On Tue, Sep 06, 2016 at 05:29:18PM +0200, Arek Bulski wrote: [I think Arek is quoting me here] One moderately stong piece of evidence would be if this function is widely available in third-party libraries and other languages. Wrong. Pytho

Re: [Python-ideas] Shuffled

2016-09-06 Thread Stephen J. Turnbull
Steven D'Aprano writes: > If your only argument is to continue to insist that Python should > have a shuffled() function and you'll write a patch, it will go no > where. First you have to convince people that the patch is needed. It's not worth the effort. The previous attempt (issue26393) to

Re: [Python-ideas] Shuffled

2016-09-06 Thread Steven D'Aprano
On Tue, Sep 06, 2016 at 05:29:18PM +0200, Arek Bulski wrote: [I think Arek is quoting me here] > > One moderately stong piece of evidence would be if this function is widely > > available in third-party libraries and other languages. > > Wrong. Python is NOT known for doing everything by how it w

Re: [Python-ideas] Shuffled

2016-09-06 Thread Arek Bulski
> And if random.shuffle() returned a new list, other people would be bitten because they expected it to be in-place. No one proposes that. shuffled() should be a new function. > One moderately stong piece of evidence would be if this function is widely available in third-party libraries and other

Re: [Python-ideas] Shuffled

2016-09-06 Thread Sven R. Kunze
If so, then I would suggest than each list provides a .shuffle method as well (just as sorted/sort does). On 06.09.2016 06:34, Mahmoud Hashemi wrote: I tend to agree with Arek. I've been bitten multiple times, including once yesterday, because shuffle works in place, when I really expect a so

Re: [Python-ideas] shuffled

2016-09-06 Thread Steven D'Aprano
On Tue, Sep 06, 2016 at 11:43:54AM +0200, Arek Bulski wrote: > They closed it. Will they accept a patch if I send it? Truth is, probably not. You would need to convince Raymond (and to a lesser extent, Tim) that this is a good idea. See my last email for the *minimum* of what you would need to

Re: [Python-ideas] shuffled

2016-09-06 Thread Eric V. Smith
On 09/06/2016 05:43 AM, Arek Bulski wrote: > They closed it. Will they accept a patch if I send it? In all likelihood, no. However, if you want to advocate for this change, and try to change their minds, I suggest you read and follow the suggestions that Steven D'Aprano gave you in an earlier emai

Re: [Python-ideas] shuffled

2016-09-06 Thread Arek Bulski
They closed it. Will they accept a patch if I send it? Where is the repo for the code? Never submitted anything to py code base. -- Arkadiusz Bulski -- ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python

Re: [Python-ideas] Shuffled

2016-09-05 Thread Steven D'Aprano
On Mon, Sep 05, 2016 at 09:34:05PM -0700, Mahmoud Hashemi wrote: > I tend to agree with Arek. I've been bitten multiple times, including once > yesterday, because shuffle works in place, when I really expect a > sorted()-like behavior for a standalone function like that. *shrug* And if random.sh

Re: [Python-ideas] Shuffled

2016-09-05 Thread Mahmoud Hashemi
I tend to agree with Arek. I've been bitten multiple times, including once yesterday, because shuffle works in place, when I really expect a sorted()-like behavior for a standalone function like that. Mahmoud https://github.com/mahmoud http://sedimental.org On Mon, Sep 5, 2016 at 6:59 PM, Arek Bu

Re: [Python-ideas] Shuffled

2016-09-05 Thread Steven D'Aprano
On Tue, Sep 06, 2016 at 03:59:10AM +0200, Arek Bulski wrote: > Implementing this in pure python wont take a lot of work. Great. Well, here's a tracker issue for it. http://bugs.python.org/issue27964 Can you provide a patch? Don't forget the tests and documentation. Providing a patch doesn't m

Re: [Python-ideas] Shuffled

2016-09-05 Thread Arek Bulski
shuffled() should be in the random module, of course. I dont suggest a builtin. Although now that you mentioned it, I could go for that too. There are usage cases where its heavily used, in randomized testing for example. I am sure that there are also other domains where randomization of lists is

Re: [Python-ideas] Shuffled

2016-09-05 Thread Chris Angelico
On Tue, Sep 6, 2016 at 11:03 AM, Steven D'Aprano wrote: > On Tue, Sep 06, 2016 at 02:50:02AM +0200, Arek Bulski wrote: > >> We should add shuffled() analog to sorted. Also shuffle() should return >> self so mutating methods could be chained. > > from random import shuffle > shuffle(mylist) > > Why

Re: [Python-ideas] Shuffled

2016-09-05 Thread Bernardo Sulzbach
On 09/05/2016 10:03 PM, Steven D'Aprano wrote: from random import shuffle shuffle(mylist) Why is that so important that it needs to be a built-in? In 15+ years of using Python, I've probably used shuffle() three or four times. Just adding to this. Sorting is a problem that comes up in almost

Re: [Python-ideas] Shuffled

2016-09-05 Thread Steven D'Aprano
On Tue, Sep 06, 2016 at 02:50:02AM +0200, Arek Bulski wrote: > We should add shuffled() analog to sorted. Also shuffle() should return > self so mutating methods could be chained. from random import shuffle shuffle(mylist) Why is that so important that it needs to be a built-in? In 15+ years of

[Python-ideas] Shuffled

2016-09-05 Thread Arek Bulski
We should add shuffled() analog to sorted. Also shuffle() should return self so mutating methods could be chained. -- Arkadiusz Bulski -- ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of