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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:08:31+00:00 2026-06-09T20:08:31+00:00

I have two list of marker objects: class Marker(): def __init__(self,marker_number, marker_data): self.marker_number =

  • 0

I have two list of marker objects:

class Marker():
    def __init__(self,marker_number, marker_data):
        self.marker_number = marker_number
        self.marker_data = marker_data

and what I want to do is this:

>>> existing_markers = [Marker(marker_number=1, marker_data= 'a'),
                     Marker(marker_number=2, marker_data= 'b'),
                     Marker(marker_number=3, marker_data= 'c'),
                     Marker(marker_number=4, marker_data= 'd'),
                     Marker(marker_number=5, marker_data= 'e'),]

>>> new_markers = [  Marker(marker_number=1, marker_data= 'aa'),
                     Marker(marker_number=3, marker_data= 'bb'),
                     Marker(marker_number=5,  marker_data= 'cc'),]

>>> interlace_markers(existing_markers, new_markers)

[Marker(marker_number=1, marker_data= 'a'),
Marker(marker_number=2, marker_data= 'aa'),
Marker(marker_number=3, marker_data= 'b'),
Marker(marker_number=4, marker_data= 'c'),
Marker(marker_number=5, marker_data= 'bb'),
Marker(marker_number=6, marker_data= 'd'),
Marker(marker_number=7, marker_data= 'e'),
Marker(marker_number=8,  marker_data= 'cc')]

So that when I interlace the markers, markers with the same number in the new_markers list as the original markers list appear after the original marker, but the numbering updates to maintain a numbered sequence. This is my current approach:

def interlace_markers(current_markers_list, new_markers_list):

    interlaced_markers = []
    #interlace the markers
    for existing_marker in current_markers_list:
        interlaced_markers.append(existing_marker)
        for new_marker in new_markers_list:
            if new_marker.marker_number== existing_marker.marker_number:
                interlaced_markers.append(new_marker)

    #reset the sequence
    sequence_index = 1
    for marker in interlaced_markers:
         marker.marker_number= sequence_index
         sequence_index += 1

    return interlaced_markers

I have two problems here:

  1. What is the most pythonic way to do this
  2. The original list will likely be large ~10k, and created from an
    external file, but the new list will be small ~100-300 long, is
    there a more efficient way of doing this rather than using lists?
  • 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-09T20:08:32+00:00Added an answer on June 9, 2026 at 8:08 pm

    If I understand you properly, I think this is most easily accomplished with simple sorting:

    interlace_markers = existing_markers + new_markers
    interlace_markers.sort(key = lambda x: x.marker_number)
    

    Now if you want to change the numbering, you can do that in a simple loop:

    for i,marker in enumerate(interlace_markers):
        marker.marker_number = i+1 #indexing is 1 based instead of zero based
    

    Note that this works because python’s sorting is stable which means that the order isn’t changed if it doesn’t have to be.

    This leads to an O(n) + O(nlogn) = O(nlogn) algorithm which isn’t too bad.

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

Sidebar

Related Questions

I have two list of different objects : List<Report> List<Newsletter> each having a 'created
Ho I have two list view on a frame layout. I want one overlay
I have two objects List<Report> List<Newsletter> I need certain properties like Id Date Status
I have two models class Market(Model): title=models.Charfield() class Product(Model): title=Models.Charfield() markets=ManyToMany(Market) And i want
I have two List<T> of objects with different types (i.e., List<Apple> and List<Tiger> ).
I have two List s of type int where I store point coordinates called
I have two list: list_a = [<User: x>, <User: y>] list_b = [False, True]
I have two list: set lista {5 6} set listb {8 9} and the
I have two list on my request on jsp. First one is productGroupName, and
i have two list, i wanted to update the second list while adding a

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.