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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:57:32+00:00 2026-06-10T01:57:32+00:00

I have several lists in python, and I would like to take only values

  • 0

I have several lists in python, and I would like to take only values which are in each list, is there any function to do it directly?

for example I have:

{'a','b','c','d','e'},{'a','g','c','d','h','e'}, {'i','b','m','d','e','a'}

and I want to make one list which contains

{'a','d','e'}

but i don’t know how many lists I actually have, cause it’s dependent on value ‘i’.

thanks for any help!

  • 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-10T01:57:33+00:00Added an answer on June 10, 2026 at 1:57 am

    if the elements are unique and hashable (and order doesn’t matter in the result), you can use set intersection: e.g.:

     common_elements = list(set(list1).intersection(list2).intersection(list3))
    

    This is functionally equivalent to:

     common_elements = list( set(list1) & set(list2) & set(list3) )
    

    The & operator only works with sets whereas the the intersection method works with any iterable.

    If you have a list of lists and you want the intersection of all of them, you can do this easily:

     common_elements = list( set.intersection( * map(set, your_list_of_lists) ) )
    

    special thanks to DSM for pointing this one out

    Or you could just use a loop:

     common_elements = set(your_list_of_lists[0])
     for elem in your_list_of_lists[1:]:
         common_elements = common_elements.intersection(elem)  #or common_elements &= set(elem) ...
     else:
         common_elements = list(common_elements)
    

    Note that if you really want to get the order that they were in the original list, you can do that using a simple sort:

    common_elements.sort( key = lambda x, your_list_of_lists[0].index(x) )
    

    By construction, there is no risk of a ValueError being raised here.

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

Sidebar

Related Questions

I have a directory with several .html files. Would like to read the list
I have a Python function which takes several arguments. Some of these arguments could
I have several unordered lists that I want to display like this: <ul> <li><img></li>
I have several hundred files in a non-flat directory structure. My Makefile lists each
I have several ReorderLists on a page. Each list has items added to it
I have a list of objects, IList<O> . O has several properties but only
Let's say I have a list in python with several strings in it. I
I have several lists in Matlab that I want to write to the same
I have several different lists I want to call. They all have the same
I have several libraries made by myself (a geometry library, a linked list library,

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.