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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:42:16+00:00 2026-05-11T16:42:16+00:00

This is a great primer but doesn’t answer what I need: Combining two sorted

  • 0

This is a great primer but doesn’t answer what I need:
Combining two sorted lists in Python

I have two Python lists, each is a list of datetime,value pairs:

list_a = [['1241000884000', 3], ['1241004212000', 4], ['1241006473000', 11]]

And:

list_x = [['1241000884000', 16], ['1241000992000', 16], ['1241001121000', 17], ['1241001545000', 19], ['1241004212000', 20], ['1241006473000', 22]]
  1. There are actually numerous list_a lists with different key/values.
  2. All list_a datetimes are in list_x.
  3. I want to make a list, list_c, corresponding to each list_a which has each datetime from list_x and value_a/value_x.

Bonus:

In my real program, list_a is actually a list within a dictionary like so. Taking the answer to the dictionary level would be:

dict = {object_a: [['1241000884000', 3], ['1241004212000', 4], ['1241006473000', 11]], object_b: [['1241004212000', 2]]}

I can figure that part out though.

  • 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-11T16:42:16+00:00Added an answer on May 11, 2026 at 4:42 pm

    Here’s some code that does what you asked for. You can turn your list of pairs into a dictionary straightforwardly. Then keys that are shared can be found by intersecting the sets of keys. Finally, constructing the result dictionary is easy given the set of shared keys.

    dict_a = dict(list_a)
    dict_x = dict(list_x)
    
    shared_keys = set(dict_a).intersection(set(dict_x))
    
    result = dict((k, (dict_a[k], dict_x[k])) for k in shared_keys)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ctypes to load a DLL in Python. This works great. Now we'd
I have been following this great guide on setting up bluetooth between 2 iPhones.
I've stumbled across this great post about validating parameters in C#, and now I
In .Net, I found this great library, HtmlAgilityPack that allows you to easily parse
I keep reading about how great this new Canvas element for HTML5 is and
I'm using Mongrel::DirHandler to control response headers for static files - this works great
In Eclipse, I can switch through open editors using control-page up/down. This works great,
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
This code involves a recursive Stored Procedure call and a not so great method
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {

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.