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

  • Home
  • SEARCH
  • 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 150729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:20:12+00:00 2026-05-11T09:20:12+00:00

I know how to get an intersection of two flat lists: b1 = [1,2,3,4,5,9,11,15]

  • 0

I know how to get an intersection of two flat lists:

b1 = [1,2,3,4,5,9,11,15] b2 = [4,5,6,7,8] b3 = [val for val in b1 if val in b2] 

or

def intersect(a, b):     return list(set(a) & set(b))   print intersect(b1, b2) 

But when I have to find intersection for nested lists then my problems starts:

c1 = [1, 6, 7, 10, 13, 28, 32, 41, 58, 63] c2 = [[13, 17, 18, 21, 32], [7, 11, 13, 14, 28], [1, 5, 6, 8, 15, 16]] 

In the end I would like to receive:

c3 = [[13,32],[7,13,28],[1,6]] 

Can you guys give me a hand with this?

Related

  • Flattening a shallow list in python
  • 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. 2026-05-11T09:20:12+00:00Added an answer on May 11, 2026 at 9:20 am

    If you want:

    c1 = [1, 6, 7, 10, 13, 28, 32, 41, 58, 63] c2 = [[13, 17, 18, 21, 32], [7, 11, 13, 14, 28], [1, 5, 6, 8, 15, 16]] c3 = [[13, 32], [7, 13, 28], [1,6]] 

    Then here is your solution for Python 2:

    c3 = [filter(lambda x: x in c1, sublist) for sublist in c2] 

    In Python 3 filter returns an iterable instead of list, so you need to wrap filter calls with list():

    c3 = [list(filter(lambda x: x in c1, sublist)) for sublist in c2] 

    Explanation:

    The filter part takes each sublist’s item and checks to see if it is in the source list c1. The list comprehension is executed for each sublist in c2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two lists: val a = List('a', 'b', 'c') val b =
which is the fastest way to find the union and intersection between two lists?
I want to intersect two genomic intervals in R. And I want to get
Does anyone know of nice C++ library to get the Union, difference and intersection
I know we can get some path with <?php bloginfo('something');?> into php files, but
I know I can get the public static members of a class by doing
I know I'll get a thousand Depends on what you're trying to do answers,
Anybody know how to get gmail's OpenID working? All I find is this http://openid-provider.appspot.com/
Anyone know how to get the position of a node using XPath? Say I
How to get to know DNS name of the server where ASP.NET application is

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.