Thanks! I opened a new thread in python-ideas, here:
https://mail.python.org/archives/list/python-id...@python.org/thread/6OLEL4XTUWXRI7ENODKEDOYFBRVDYKI7/
The "first" thread was very long, and was focused on a
different function, first(). Perhaps a new thread, focused on one simple
function in it
On Tue, 28 Jul 2020 at 15:16, Brett Cannon wrote:
> For ideas like this it is best to discuss them on python-ideas.
>
> I'll also mention that this idea has been brought up at least twice
> before: search for threads about itertools and single() or first() (if I
> remember correctly).
>
I think "
For ideas like this it is best to discuss them on python-ideas.
I'll also mention that this idea has been brought up at least twice before:
search for threads about itertools and single() or first() (if I remember
correctly).
On Mon, Jul 27, 2020 at 12:07 PM Noam Yorav-Raphael
wrote:
> Hi,
>
>
I'm sorry, I don't think I got that. I don't find a mailing list called
itertools-ideas. Do you mean this should go to python-ideas? If so, I'm
sorry for bothering python-dev, and I'll move this to python-ideas.
I just read "The python-ideas list is for discussing more speculative
design ideas" (h
Shouldn’t this go to itertools-ideas? :-)
On Mon, Jul 27, 2020 at 13:56 David Mertz wrote:
> I don't like consuming the iterator in the exception case. You might
> expect just one, but have a fallback approach for more. You could build the
> safer behavior using itertools.tee() or itertools.chai
I don't like consuming the iterator in the exception case. You might expect
just one, but have a fallback approach for more. You could build the safer
behavior using itertools.tee() or itertools.chain().
On Mon, Jul 27, 2020, 3:10 PM Noam Yorav-Raphael wrote:
> Hi,
>
> There's a simple function
Thanks for the suggestion! I agree that using a list is clearer that having
a trailing comma, I like it!
I still think that having a one() function would be useful, since:
1. I think it spells the intention more clearly. Also the exception would
be easier to understand, since errors in tuple unpac
I would think that you can use tuple unpacking for this?
single_element, = some_iterator
Will attempt to unpack the some_iterator into single_element and fail if
single_element doesn't have exactly 1 element. It also has the added
benefit that it works for any number of elements:
one, two =
On Tue, Jul 28, 2020 at 5:24 AM Steven Barker wrote:
>
> A single-name unpacking assignment can do exactly what you want, albeit with
> slightly less helpful exception messages:
>
> jack, = (p for p in people if p.id == '1234') # note comma after the name
> jack
>
Agreed. As a minor readabi
A single-name unpacking assignment can do exactly what you want, albeit
with slightly less helpful exception messages:
jack, = (p for p in people if p.id == '1234') # note comma after the
name jack
If no value is yielded by the generator expression, you'll get "ValueError:
not enough values t
I second this as being useful.
However the “pythonic” way (whatever that means nowadays) is to do a for break
else loop, which I think is kinda difficult to read as you need to make a few
assumptions.
Rollo
> On 27 Jul 2020, at 20:06, Noam Yorav-Raphael wrote:
>
>
> Hi,
>
> There's a simp
11 matches
Mail list logo