[Tutor] Discussion about Chaining in comparison operators
Joel Goldstick
joel.goldstick at gmail.com
Tue Oct 6 21:00:35 EDT 2020
On Tue, Oct 6, 2020 at 8:50 PM Alan Gauld via Tutor <tutor at python.org> wrote:
>
> On 07/10/2020 01:09, Joel Goldstick wrote:
>
> >> Our objective should *always* be to write the most readable(*)
> >> code we can.
> >>
> >> So yes, a==b==c wins.
>
> > another way is:
> >
> >>>> a=3
> >>>> b=4
> >>>> c=3
> >>>> len(set((a,b,c)))
>
> > if they are all the same the set will be of length 1.
>
>
> That's true but it is neither readable nor performant.
> It requires an act of thought to recognize that 3 items
> into a set of length 1 means they are all the same.
> That's much less readable than a direct equality test.
> And much slower since you have to construct a set.
>
> a==b==c
>
> still wins
>
I think you win the argument, but I've noticed sets to be
underappreciated at times.
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
More information about the Tutor
mailing list