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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:16:46+00:00 2026-06-10T23:16:46+00:00

I have two lists. One list contains only codes e.g.: b3b 3cd 6f6 4d8

  • 0

I have two lists.

One list contains only codes e.g.:

b3b
3cd
6f6
4d8
96b
00a
774
eb3
607
7e5

The other list contains code with names e.g.

b3b:John
607:Eric
7e5:Jarrold

But the list is not compleet yet.

What I want as output, because the other cannot be removed and has to be in the right order, e.g.

b3b:John
3cd
6f6
4d8
96b
00a
774
eb3
607:Eric
7e5:Jarrold

Already have this code but it only returns True or False but that’s not what I want.

list1 = [line.strip() for line in open('list1')]
list2 = [line.strip() for line in open('list2')]

comp = [i[:3] for i in list2]

for i in list1:
    print(i, i in list2)

Maybe anyone who can help me with this?

  • 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-10T23:16:48+00:00Added an answer on June 10, 2026 at 11:16 pm

    You should use a dictionary mapping keys to names instead of a list as the second data structure:

    with open("list1") as f:
        keys = [line.strip() for line in f]
    with open("list2") as f:
        names = dict(line.strip().split(":", 1) for line in f)
    

    Now you can efficiently implement your loop:

    for k in keys:
        print(k, names.get(k, ""))
    

    Performing a linear search in list2 for every entry of list1 would be rather inefficient. Apart from the better performance, a dictionary is also a better model of the meaning of your data.

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

Sidebar

Related Questions

I have one drop down list in my page, which contains two options. What
I have two lists. They are sortable but not connected (elements of list one
I have two lists in a dialog - one bubble count list and one
I have two list on my request on jsp. First one is productGroupName, and
Ho I have two list view on a frame layout. I want one overlay
I currently have two SQL commands. One retrieves a list of unique IDs from
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two JTables. One is for the list of invoices and the other
I have two different arrays. One array, a, for a list of people. My
I have an excel spreadsheet with two columns, one with a list of exercises

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.