Put this comparison in a function! The current behavior is what I wish '==' to do, and what millions of lines of Python code assume. A tuple is not a list is not an array. I don't want an equality comparison to lie to me.
You can write a few lines to implement 'has_same_items(a, b)' that will behave the way you want. On Sat, May 2, 2020, 2:36 PM Ahmed Amr <ahmedam...@gmail.com> wrote: > I see there are ways to compare them item-wise, I'm suggesting to bake > that functionality inside the core implementation of such indexed > structures. > Also those solutions are direct with tuples and lists, but it wouldn't be > as direct with arrays-lists/tuples comparisons for example. > > On Sat, 2 May 2020, 6:58 pm Antoine Rozo, <antoine.r...@gmail.com> wrote: > >> (and a check on the length or zip_longest to ensure that there is no >> other items) >> >> Le sam. 2 mai 2020 à 18:53, Antoine Rozo <antoine.r...@gmail.com> a >> écrit : >> > >> > And if you can't / don't want to create new lists for the values you >> > want to compare, a solution could be to use zip & all builtins: >> > >> > print(all(a == b for a, b in zip(tuple_, list_))) >> > >> > Le sam. 2 mai 2020 à 16:58, Steele Farnsworth <swfarnswo...@gmail.com> >> a écrit : >> > > >> > > You can get the desired behavior by casting a list to a tuple, or a >> tuple to a list, in the equality statement. That way those that rely on the >> existing implementation don't have to change their code. >> > > >> > > my_tup = (1, 2, 3) >> > > my_list = [1, 2, 3] >> > > print(list(my_tup) == my_list) >> > > >> > > On Sat, May 2, 2020, 9:04 AM Ahmed Amr <ahmedam...@gmail.com> wrote: >> > >> >> > >> I'd like to take your opinion on modifying some of the indexed >> collections like tuples, lists, arrays to evaluate its equality to True >> when having the same items in the same indexes. >> > >> Currently, when comparing a list of items to an array of the same >> items for equality (==) it returns False, I'm thinking that it would make >> sense to return True in that context, as we're comparing item values and we >> have the same way of indexing both collections, so we can compare item >> values. >> > >> >> > >> So what do you think about applying such behavior on collections >> that can be indexed the same way such as tuples, lists, and arrays? >> > >> >> > >> Example: (Current) >> > >> >> > >> import array >> > >> tuple_ = (1.1, 2.2, 3.3) >> > >> list_ = [1.1, 2.2, 3.3] >> > >> array_ = array.array('f', [1.1, 2.2, 3.3]) >> > >> >> > >> # all of the following prints False. >> > >> print(tuple_ == list_) >> > >> print(tuple_ == array_) >> > >> print(array_ == list_) >> > >> >> > >> Example: (Proposed): >> > >> All prints above to show True as they are populated with the same >> data in the same indexes. >> > >> >> > >> A Side Note: >> > >> An extra point to discuss, based on arrays implementation, >> array_.to_list() would actually get [1.100000023841858, 2.200000047683716, >> 3.299999952316284] which is not exactly what we've passed as args and this >> is normal, but I'm thinking about leaving it to the array implementation to >> encapsulate that implementation and perform exact equality based on passed >> arguments. >> > >> _______________________________________________ >> > >> 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/archives/list/python-ideas@python.org/message/UE5HGECRTS3ERK5OMG3GB77EKSAFJV7R/ >> > >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > > >> > > _______________________________________________ >> > > 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/archives/list/python-ideas@python.org/message/NPEIUL3A7JYPFTDLVLOOENT5UXFYJKUT/ >> > > Code of Conduct: http://python.org/psf/codeofconduct/ >> > >> > >> > >> > -- >> > Antoine Rozo >> >> >> >> -- >> Antoine Rozo >> _______________________________________________ >> 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/archives/list/python-ideas@python.org/message/HSJP5SF6HVVGOHSYROQDGV6HNSYWK7TR/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > _______________________________________________ > 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/archives/list/python-ideas@python.org/message/QOFW3MQEWNUY66DFZXC37ILI2XSXHONA/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/archives/list/python-ideas@python.org/message/XHUDBYMQ65CHG3QTXHS4EXIH5JNW52IN/ Code of Conduct: http://python.org/psf/codeofconduct/