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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:40:48+00:00 2026-05-29T21:40:48+00:00

So, I have 3 lists as follows: list_1 = [‘a’,’b’,’c’] list_2 = [‘b’,’c’] list_3

  • 0

So, I have 3 lists as follows:

list_1 = ['a','b','c'] 
list_2 = ['b','c']
list_3 = [5,4]

I am looking to generate a fourth list of values from list_2 & list_3 that will map to list_1. list_2 and list_3 are independent of list_1 but are subsets of list_1 and do map to each other. i.e list_2 and list_3 is missing item ‘a’ and corresponding values.

I want to handle the missing values and assign some value i.e 0 or empty string. I would like to do this with an inline function. so far, I have tried the following but it fails. What am I doing wrong?

list_4 =[lambda i:list_3[list_2.index(list_1[i])] except "" for i in range(len(list_1))]

My final result should look like this:

list_4=[0,5,4]
  • 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-29T21:40:52+00:00Added an answer on May 29, 2026 at 9:40 pm

    Why don’t you check for the presence of the value, instead of relying on exception handling?

    list_4 = [(list_3[list_2.index(item)] if item in list_2 else 0) for index,item in enumerate(list_1)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lists where strings correspond with values. For example, in a company list
If I have a drop down list as follows <div class=editor-label> <%= Html.DropDownListFor(model =>
I have a list stored in resultlist as follows: var resultlist = results.ToList(); It
I have a UL List set up as follows: <div id=menu> <ul> <li> <a
I have a class as follows :- interface IFilterCondition { List<Name> ApplyFilter(List<Name> namesToFilter); }
I have defined a drop down list in html as follows. I have appended
I have a map declared as follows: map < string , list < string
I have a list of lists, eg [[1;2;3];[2];[3;4;5;6]; [7;8;9;10] I want to place these
I have a list of comprising of sub-lists with different numbers of entries, as
I have data from two tables in a members system as follows: Table: listuser

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.