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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:08:30+00:00 2026-05-22T17:08:30+00:00

I got a list of objects which look like strings, but are not real

  • 0

I got a list of objects which look like strings, but are not real strings (think about mmap’ed files). Like this:

x = [ "abc", "defgh", "ij" ]

What i want is x to be directly indexable like it was a big string, i.e.:

(x[4] == "e") is True

(Of course I don’t want to do “”.join(x) which would merge all strings, because reading a string is too expensive in my case. Remember it’s mmap’ed files.).

This is easy if you iterate over the entire list, but it seems to be O(n). So I’ve implemented __getitem__ more efficiently by creating such a list:

x = [ (0, "abc"), (3, "defgh"), (8, "ij") ]

Therefore I can do a binary search in __getitem__ to quickly find the tuple with the right data and then indexing its string. This works quite well.

I see how to implement __setitem__, but it seems so boring, I’m wondering if there’s not something that already does that.

To be more precise, this is how the data structure should honor __setitem__:

>>> x = [ "abc", "defgh", "ij" ]
>>> x[2:10] = "12345678"
>>> x
[ "ab", "12345678", "j" ]

I’d take any idea about such a data structure implementation, name or any hint.

  • 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-22T17:08:31+00:00Added an answer on May 22, 2026 at 5:08 pm

    What you are describing is a special case of the rope data structure.

    Unfortunately, I am not aware of any Python implementations.

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

Sidebar

Related Questions

I've got a potentially rather large list of objects I'd like to bind to
i got a generic list that looks like this: List<PicInfo> pi = new List<PicInfo>();
i got a class which holds info about pictures, like filepath, hashvalue, bytes. in
I've got a list which stores a number of objects. Each object has a
I've got a list of objects (probably not more than 100), where each object
I've got a list of objects (properties for rent, in this case) that I
I've got a list of objects List[Object] which are all instantiated from the same
I've got a list of UserControl objects; when a menu option is clicked to
In the project I'm working on I have got a list List<Item> with objects
I've got a Fitnesse RowFixture that returns a list of business objects. The object

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.