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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:49:47+00:00 2026-05-22T15:49:47+00:00

I am have two lists: a= [[‘A’, ‘B’, ‘C’, 3], [‘P’, ‘Q’, ‘R’, 4]]

  • 0

I am have two lists:

a= [['A', 'B', 'C', 3], ['P', 'Q', 'R', 4]]

b=[['K',1,1,1,1,1], ['L',1,1,1,1,1], ['M', 1,1,0,1,1], ['J', 0,0,0,0,0], ['A', 0,0,0,1,1], ['P',0,1,0,1,1 ]]

I want the output like:

Output=[['A', 0,0,0,1,1], ['P',0,1,0,1,1 ]]

I am trying to search the a in b using the a[idx][0]. Then I want to collect those items and would like the Output something like above.

My code looks like:

Output=[]
for idx in range(len(Test)):
    a_idx = [y[0] for y in b].index(a[idx][0])
    a_in_b = b[a_idx]
    Output.append(a_in_b[:])

print Output 

This does not give me the desired output. Can someone please 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-05-22T15:49:48+00:00Added an answer on May 22, 2026 at 3:49 pm

    While eumiro’s answer is a better one, you asked for a version which uses index. My version seems to work consistently:

    a= [['A', 'B', 'C', 3], ['P', 'Q', 'R', 4]]
    b=[['K',1,1,1,1,1], ['L',1,1,1,1,1], ['M', 1,1,0,1,1], ['J', 0,0,0,0,0], ['A', 0,0,0,1,1], ['P',0,1,0,1,1 ]]
    src = [y[0] for y in b]; # I moved this out here so that it is only calculated once
    Output = []
    for i in range(len(a)):  # You have Test here instead??? Not sure why
         ai  = src.index( a[ i ][ 0 ] )
         Output.append( b[ ai ][:] )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists of objects, using Linq I would like to merge them,
I have two lists of custom objects and want to update a field for
I have two lists and I want to select items that are not in
I have two lists which are guaranteed to be the same length. I want
I have two lists and I want to see what the two lists DON'T
I have two lists xscat and yscat. I would like the list comprehension to
I have two lists or more than . Some thing like this: listX =
I have two lists List<WorkOrder> and List<PlannedWork> I would like join the two lists
I have two lists with data that I want to compare dates for. I
I have two lists: ListA: Brown Green Yellow Orange ListB: Yellow Orange I want

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.