Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4083010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:15:31+00:00 2026-05-20T18:15:31+00:00

I hope this hasn’t been asked before but it’s hard for me to put

  • 0

I hope this hasn’t been asked before but it’s hard for me to put into words what it is I’m trying to do!

It might be easier if I explain my input, and desired output

l1 = [[(14, 'h'), (14, 'd')], [(14, 'h'), (14, 'c')], [(14, 'h'), (14, 's')], [(14, 'd'), (14, 'c')], [(14, 'd'), (14, 's')], [(14, 'c'), (14, 's')], [(13, 'h'), (13, 'd')], [(13, 'h'), (13, 'c')], [(13, 'h'), (13, 's')], [(13, 'd'), (13,'c')], [(13, 'd'), (13, 's')], [(13, 'c'), (13, 's')], [(12, 'h'), (12, 'd')], [(12, 'h'), (12, 'c')], [(12, 'h'), (12, 's')], [(12, 'd'), (12, 'c')], [(12, 'd'), (12, 's')], [(12, 'c'), (12, 's')]]

l2 = [(13,'h'),(13,'d'),(14,'c'),(14,'s'),(14,'h')]

So this first list, l1, is a list of lists, each list is a poker hand of 2 cards.

Basically what I’m trying to do is if a card is in l2, the hand in l1 needs to be removed. So the entry [(14,’d’),(14,’c’)] needs to be removed from l1 because (14,’c’) is in l2– even though (14,’d’) isn’t in l2.

The desired output from this example should be,

[[(13, 'c'), (13, 's')], [(12, 'h'), (12, 'd')], [(12, 'h'), (12, 'c')], [(12, 'h'), (12, 's')], [(12, 'd'), (12, 'c')], [(12, 'd'), (12, 's')], [(12, 'c'), (12, 's')]]

I thought about iterating over all the tuples inside l1 and removing them if they’re in l2, then afterwards go back and iterate over the lists in l1 and remove any without len == 2. This doesn’t seem like the best way to go, though.

Any thoughts?

ManyTIA!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:15:32+00:00Added an answer on May 20, 2026 at 6:15 pm
    l2_set = set(l2)
    # or use 
    #   l2_set = {(13,'h'),(13,'d'),(14,'c'),(14,'s'),(14,'h')}
    # directly
    
    l1 = [hand for hand in l1 if not (hand[0] in l2_set or hand[1] in l2_set)]
    

    If the entry may contain ≥2 members, you could generalize the filter condition to

    l1 = [hand for hand in l1 if all(subhand not in l2_set for subhand in hand)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this hasn't been asked before. I have a nullable boolean called boolIsAllowed
I hope that this question hasn't been asked already, but I was looking for
Hope this question hasn't been asked before. I've got the following working <!-- 640x920
I hope this question (or one similar) hasn't been asked before. Sincere apologies if
I hope this hasn't been asked and I just missed it, but I searched
I hope this hasn't been asked before, if so I apologize. EDIT: For clarity,
I hope this hasn't been asked yet, since I couldn't find it. I am
I hope this hasn't already been answered, but I feel like I have read
hope this wasn't asked already, but I can't find an answer. I got a
i hope this hasn't already been answered, I've looked through for awhile and haven't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.