Nice!
On Sun, Oct 25, 2020 at 9:59 PM Dennis Sweeney
wrote:
> What if the mapping assignment were more harmonious with the pattern
> matching PEP? Something like this:
>
> items = {'eggs': 2, 'cheese': 3, 'spam': 1}
> {'eggs': eggs, 'spam': i_dont_need_to_name_this_spam, **rest} = items
What if the mapping assignment were more harmonious with the pattern matching
PEP? Something like this:
items = {'eggs': 2, 'cheese': 3, 'spam': 1}
{'eggs': eggs, 'spam': i_dont_need_to_name_this_spam, **rest} = items
assert i_dont_need_to_name_this_spam == 1
assert eggs == 2 and
On Mon, Oct 26, 2020 at 10:47 AM Cameron Simpson wrote:
>
> On 26Oct2020 09:45, Chris Angelico wrote:
> >On Mon, Oct 26, 2020 at 8:44 AM Cameron Simpson wrote:
> >> On 24Oct2020 13:37, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
> >> >Spaces in filenames are just as bad, and much
On 26Oct2020 09:45, Chris Angelico wrote:
>On Mon, Oct 26, 2020 at 8:44 AM Cameron Simpson wrote:
>> On 24Oct2020 13:37, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
>> >Spaces in filenames are just as bad, and much more common:
>>
>> But much easier to handle in simple text listings,
this seems nice.
It just seems that the obvious way to do it would be:
def tap(iter_, func):
for item in iter_:
func(item)
yield item
I think it can be nice, but more as cookbook material than an actual
itertools function.
On Sun, 25 Oct 2020 at 14:38,
On Sun, Oct 25, 2020, at 18:45, Chris Angelico wrote:
> If you actually DO need to read null-terminated records from a file
> that's too big for memory, it's probably worth just rolling your own
> buffering, reading a chunk at a time and splitting off the interesting
> parts. It's not hugely
On Mon, Oct 26, 2020 at 8:44 AM Cameron Simpson wrote:
>
> On 24Oct2020 13:37, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
> >On 2020-10-24 at 12:29:01 -0400,
> >Brian Allen Vanderburg II via Python-ideas wrote:
> >
> >> ... Find can output it's filenames in null-terminated lines
On 24Oct2020 13:37, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
>On 2020-10-24 at 12:29:01 -0400,
>Brian Allen Vanderburg II via Python-ideas wrote:
>
>> ... Find can output it's filenames in null-terminated lines since it
>> is possible to have newlines in a filename(yuck) ...
>
On 2020-10-25 at 16:34:14 +,
George Harding wrote:
> some_iter = map(lambda x: x if print(x) else x, some_iter)
>
> The tuple has a ~50% overhead, the case statement ~15%, compared to the
> generator.
def print_first(x):
print(x)
return x
new_iter = map(print_first,
less awkward is:
some_iter = map(lambda x: x if print(x) else x, some_iter)
The tuple has a ~50% overhead, the case statement ~15%, compared to the
generator.
I think that the less awkward syntax solves the problem fine (if you can
come up with it). I like that it's explicit rather than
This seems like it might be a reasonable thing to have in intertools? It's
not hard to write this sort of thing with map:
some_iter = map(lambda x: (print(x), x)[1], some_iter)
But it's a little awkward. (Though maybe I'm missing a less awkward way to
do that.)
Java has Stream.peek for similar
Python has many tools for iteration, such as map and filter, that change an
iterator into another iterator without consuming the iterator. These make it
simple to deal with many items in a list without consuming excessive memory.
Occasionally it is useful to be able to tap into iterator items
I've been toying with a similar idea myself. I've felt the pain
described by Brian, and I share Marco's dislike for the suggested
syntax. Moreover, I dislike the idea that the conditional should
somehow refer to the function's default arguments.
My half-baked idea is along the lines of
13 matches
Mail list logo