<br>
<br><br><div class="gmail_quote">On Wed, May 16, 2012 at 1:46 AM, Mike Meyer <span dir="ltr"><<a href="mailto:mwm@mired.org" target="_blank">mwm@mired.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, 16 May 2012 01:08:09 -0700<br>
<div class="im">Bruce Leban <<a href="mailto:bruce@leapyear.org">bruce@leapyear.org</a>> wrote:<br>
> On Wed, May 16, 2012 at 12:40 AM, Mike Meyer <<a href="mailto:mwm@mired.org">mwm@mired.org</a>> wrote: </div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">> I didn't claim it was fast. I actually wrote that version instead of the<br>
> in/return version for a very specific reason: it always returns the same<br>
> element. (The for/in/return version might return the same element every<br>
> time too but it's not guaranteed.)<br>
<br>
</div>I didn't ask for a get that would always return the same element.<br></blockquote><div><br></div><div>You didn't ask for a get that *didn't* always return the same element. My deterministic version is totally compatible with your ask here and </div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Would you also complain that having int accept a string value in lieu<br>
of using eval on untrusted input is a case of "it's useful anytime you<br>
need it."?<br></blockquote><div><br></div><div>Not at all. It's useful because it's very common to need to convert strings to numbers and I can show you lots of code that does just that. So we need a method that does that safely. Does it have to be int? No; it could be atoi or parse_int or scanf. But we do need it.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> I don't think your test is very good if it uses the get I wrote<br>
> above. Your test will only operate on one element of the set and<br>
> it's easy to write functions which succeed for some elements of the<br>
> set and fail for others. I'd like to see an actual test that you<br>
> think needs this that would not be improved by iterating over the<br>
> list.<br>
<br>
</div>Talk about tautologies! Of course you can write tests that will fail<br>
in some cases. You can also write tests that won't fail for your<br>
cases. Especially if you know something about the set beforehand.<br></blockquote><div><br></div><div>Not what I said. It's easy to write a *function* that fails on some elements and your *test* won't test it. Example: a function that fails when operating on non-integer set elements or the largest element or .... Your test only tests an one case. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
For instance, I happen to know I have a set of ElementTree elements<br>
that all have the same tag. I want to check the tag.<br></blockquote><div><br></div><div>Then maybe you should be using a different data structure than a set. Maybe set_with_same_tag that declares that constraint and can enforce the constraint if you want.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
One of the test cases starts by checking to see if the set is a<br>
singleton. Do you really propose something like:<br>
<br>
if len(s) == 1:<br>
for i in s:<br>
res = process(i)<br>
<br></blockquote><div>This is a legitimate use case. I don't think it's a big deal to have to add a one line function to your code. I might even use EAFP:</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div class="gmail_quote"><div>res = process(set_singleton(s))</div></div></blockquote><div class="gmail_quote"><div><br></div><div>where</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div class="gmail_quote"><div>def set_singleton(s):</div><div> [result] = s</div><div> return result</div></div></blockquote><br><div>--- Bruce</div>