Python Forum
Check common element in tuples
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check common element in tuples
#11
That's awesome, thank you !

The good answer, for my need, was this one :

def find_matches(tuples):
    result = [False]  # <- Was incorrectly set to True
    for i in range(len(tuples)-1):
        pair = list(set(tuples[i])) + list(set(tuples[i+1]))  // Protect against duplicates in a list
        result.append(len(set(pair)) != len(pair))  # And corresponding error here.
    return result
                     
print(find_matches([(45,50,30,21), (30,9,56,3), (57,10,21,4), (41,30,50,56)]))
Thank you again.
Reply


Messages In This Thread
Check common element in tuples - by PUP280 - Nov-01-2020, 03:42 PM
RE: Check common element in tuples - by deanhystad - Nov-01-2020, 04:14 PM
RE: Check common element in tuples - by PUP280 - Nov-01-2020, 04:55 PM
RE: Check common element in tuples - by deanhystad - Nov-01-2020, 05:32 PM
RE: Check common element in tuples - by deanhystad - Nov-01-2020, 05:54 PM
RE: Check common element in tuples - by jefsummers - Nov-01-2020, 07:55 PM
RE: Check common element in tuples - by deanhystad - Nov-01-2020, 09:51 PM
RE: Check common element in tuples - by perfringo - Nov-02-2020, 09:18 AM
RE: Check common element in tuples - by deanhystad - Nov-02-2020, 07:05 PM
RE: Check common element in tuples - by volcano63 - Nov-02-2020, 07:25 PM
RE: Check common element in tuples - by PUP280 - Nov-05-2020, 05:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,257 Jun-14-2022, 08:35 PM
Last Post: thesquid
  check if element is in a list in a dictionary value ambrozote 4 2,009 May-11-2022, 06:05 PM
Last Post: deanhystad
  How to check if my argument is a tuple with 3 tuples zarox 1 1,845 Nov-15-2020, 06:50 PM
Last Post: DougBTX
  Unable to locate element no such element gahhon 6 4,540 Feb-18-2019, 02:09 PM
Last Post: gahhon
  Change single element in 2D list changes every 1D element AceScottie 9 12,121 Nov-13-2017, 07:05 PM
Last Post: Larz60+
  common elements of a list Skaperen 5 9,456 Mar-22-2017, 10:13 AM
Last Post: buran
  Check to see if a string exactly matches an element in a list DBS 1 22,345 Nov-02-2016, 10:16 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020