On 2021-10-25 5:32 a.m., Jeremiah Vivian wrote:
For quick checking if a `Movement` object is inside of an iterable.
It seems the core of your problem is that you took the mechanism that's
supposed to tell you if two objects are identical for another purpose,
and now are complaining that you d
On Thu, Oct 28, 2021 at 3:04 AM Steven D'Aprano
> The "in" operator is built on iteration, but can be overridden by the
> `__contains__` method.
I would say it is built on __contains__, but will fall back on iteration :-)
Effectively the same, but conceptually a bit different.
There is also th
> On Thu, Oct 28, 2021 at 05:25:52PM +1100, Chris Angelico wrote:
>> But the "in" operator isn't built on iteration, so that would be
>> in-consistent.
>
> "In-"consistent, heh :-)
>
> \>\>\> a = iter("abcde")
> \>>> a.__contains__
> Traceback (most recent call last):
> File "", li
On Thu, Oct 28, 2021 at 9:05 PM Steven D'Aprano wrote:
>
> On Thu, Oct 28, 2021 at 05:25:52PM +1100, Chris Angelico wrote:
>
> > But the "in" operator isn't built on iteration, so that would be
> > in-consistent.
>
> "In-"consistent, heh :-)
Couldn't resist.
> >>> a = iter("abcde")
> >>
On Thu, Oct 28, 2021 at 10:09 PM Jeremiah Vivian
wrote:
>
> I don't quite understand completely the major first part of your reply...
Please quote text so we know who you're replying to.
ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
T
I don't quite understand completely the major first part of your reply...
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org
> What you're asking for can best be spelled with any/all and iteration,
> not a new operator.
I can settle with this.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.pyth
On Thu, Oct 28, 2021 at 05:25:52PM +1100, Chris Angelico wrote:
> But the "in" operator isn't built on iteration, so that would be
> in-consistent.
"In-"consistent, heh :-)
>>> a = iter("abcde")
>>> a.__contains__
Traceback (most recent call last):
File "", line 1, in
Att
On Thu, Oct 28, 2021 at 4:52 PM Jeremiah Vivian
wrote:
>
> All containers do have a concept of iterators though, and the `is in`
> operator can check using the iterator of the container.
>
But the "in" operator isn't built on iteration, so that would be in-consistent.
What you're asking for can
All containers do have a concept of iterators though, and the `is in` operator
can check using the iterator of the container.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://m
On Mon, Oct 25, 2021 at 9:33 PM Jeremiah Vivian
wrote:
>
> > It's worth noting that "in" is defined by the container. Object
> > identity and equality aren't actually part of the definition. A lot of
> > containers will behave as the OP describes, but strings, notably, do
> > not - if you iterate
> It's worth noting that "in" is defined by the container. Object
> identity and equality aren't actually part of the definition. A lot of
> containers will behave as the OP describes, but strings, notably, do
> not - if you iterate over "caterpillar", you will never see "cat", yet
> it is most def
On Mon, Oct 25, 2021 at 8:35 PM Steven D'Aprano wrote:
>
> Otherwise, it would silently do the wrong thing. And then the coder who
> accidentally inserts an unneeded `is` into the test will have to deal
> with weird implementation-dependent silent failures due to caching of
> small ints and string
*It should be obvious
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archi
It should make sense that if an operation is grammatically correct in a
programming language, there's something wrong there. There could be alternative
syntax,
> 'is `object` in `iterable`'
or
> 'is `object` not in `iterable`'
but I feel like there's some disadvantage to this alternative syntax.
On Mon, Oct 25, 2021 at 08:39:19AM -, Jeremiah Vivian wrote:
> If I wanted to check if an *exact* object is in an iterable
A nice way to check for exact identity in an iterable is this:
any(value is element for element in iterable)
That stops on the first match, and is pretty efficient.
For quick checking if a `Movement` object is inside of an iterable.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Mess
On Mon, Oct 25, 2021 at 8:09 PM Jeremiah Vivian
wrote:
>
> Something like this:
> > \>\>\> class Movement:
> > ... def __eq__(self, x):
> > ... return type(x) is Movement
> > ...
Uhh, why are you defining equality in this bizarre way? Every Movement
is equal to every other?
ChrisA
__
Something like this:
> \>\>\> class Movement:
> ... def __eq__(self, x):
> ... return type(x) is Movement
> ...
> \>\>\> dummy = Movement()
> \>\>\> # suppose `bar` is a list of every recorded action in a game
> \>\>\> if dummy in bar:
> ... if dummy is in bar: # check if the dummy
On Mon, Oct 25, 2021 at 7:40 PM Jeremiah Vivian
wrote:
>
> I DO expect this thread to be bombarded with negative replies.
>
> Currently, there are `in`/`not in` operators which work like this in Python:
> > def contains(contains_value, iterable, not_in):
> > for element in iterable:
> >
20 matches
Mail list logo