Interesting to look at the code for some of this.
list.repr and dict.repr seem to be taking the "construct a set of seen
items" approach. Except it's not using a set of ids, it's doing a linear
pass over a list of visited PyObjects each time (which seems somewhat
surprising to me, though it's only
> that can be used (eg) for indexing
Even without it being used in as complicated a way as that it's *still* not
backward compatible because of the trivial case, as foo.endswith("") is
True.
On Sun, Aug 8, 2021 at 11:55 PM Chris Angelico wrote:
> On Mon, Aug 9, 2021 at 1:42 PM wrote:
> >
> > T
I was just saying that using the bool return value as an index is a bit
obscure, compared to using it as a condition in an if statement. But even
in the more common use, returning the matched string is still a chance in
behavior.
On Mon, Aug 9, 2021, 10:13 AM Chris Angelico wrote:
> On Tue, Aug
The error message for using a mutable sequence as a set item or map key
seems to frequently confuse Python beginners. The current wording is:
>>> {[1, 2, 3]: [4, 5, 6]}
TypeError: unhashable type: 'list'
The first thing a Google search finds for "unhashable type" is ~4k Stack
Overflow results lik
sion. I do
think it can be useful to have more direct links to documentation, though.
> at least add "unhashable" to the glossary -- after all, both "mutable"
and "immutable" are in there.
I think that's reasonable.
On Mon, Sep 28, 2020 at 11:41 AM Christophe
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 f
datetime.datetime has microsecond precision, and if you want to reconstruct
a datetime from microseconds since the Unix epoch in a provided timezone,
you can do:
(datetime(1970, 1, 1, tzinfo=timezone.utc) +
timedelta(microseconds=timestamp_us)).astimezone(tz)
This is a general solution, but it co
p> wrote:
> Samuel Freilich via Python-ideas writes:
>
> > This might all be too much thought about edge cases that don't
> > matter, but given the *_ns() functions in the time module (PEP
> > 564), I'm curious why datetime doesn't have a constructor