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


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,224 Jun-14-2022, 08:35 PM
Last Post: thesquid
  check if element is in a list in a dictionary value ambrozote 4 1,963 May-11-2022, 06:05 PM
Last Post: deanhystad
  How to check if my argument is a tuple with 3 tuples zarox 1 1,824 Nov-15-2020, 06:50 PM
Last Post: DougBTX
  Unable to locate element no such element gahhon 6 4,462 Feb-18-2019, 02:09 PM
Last Post: gahhon
  Change single element in 2D list changes every 1D element AceScottie 9 12,065 Nov-13-2017, 07:05 PM
Last Post: Larz60+
  common elements of a list Skaperen 5 9,411 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,288 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