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 8829483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:50:34+00:00 2026-06-14T07:50:34+00:00

Imagine a function: def Intersects (x, list1, list2, list3): if x in list1 and

  • 0

Imagine a function:

def Intersects (x, list1, list2, list3):
    if x in list1 and x in list2 and x in list3: return True
    return False

There has to be a better way to do this but I can’t figure it out. How can I do this? (performance is important)

EDIT: I’ve come across a related, however harder problem this time. This time I’ve got 3 unrelated integers and I need to test if they intersect too.

Like:

1, 2, 3 <-- elements to look for
if InAll ((1, 2, 3)) ...

but I am not looking for a tuple, instead I am looking for just integers. How do I unpack the tuple and do the same search?

  • 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-06-14T07:50:36+00:00Added an answer on June 14, 2026 at 7:50 am

    If you want to be able to give it any number of lists (not just three), you might like:

    def inAll(x, *lsts):
        return all((x in l) for l in lsts)
    

    If you are checking memberships in these lists many times (on many xs, that is), you’ll want to make each into a set before you start looping through the xs.

    From your most recent edit, it looks like you also want to be able to pass multiple items in x. Code for that would be:

    def inAll(xs, *lsts):
        return all(all(x in l for x in xs) for l in lsts)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
Imagine I want to map a function over an array, but the function has
Let's imagine that we have object Animal $.Animal = function(options) { this.defaults = {
imagine there are two interfaces arranged via composite pattern, one of them has a
Context: Imagine that you have a standard CherryPy hello word app: def index(self): return
Imagine this function: void SoundManager::playSource(ALuint sourceID, float offset) { alSourceStop(sourceID); ALint iTotal = 0;
Imagine I have a class in C# called Bar that has a public function
Imagine this code: class Foo { println(in Foo) def foo(a: Int) = a +
Imagine I have a class Window with a member function show which causes the

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.