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

The Archive Base Latest Questions

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

I have a large list l . I want to create a view from

  • 0

I have a large list l. I want to create a view from element 4 to 6. I can do it with sequence slice.

>>> l = range(10)
>>> lv = l[3:6]
>>> lv
[3, 4, 5]

However lv is a copy of a slice of l. If I change the underlying list, lv does not reflect the change.

>>> l[4] = -1
>>> lv
[3, 4, 5]

Vice versa I want modification on lv reflect in l as well. Other than that the list size are not going to be changed.

I’m not looking forward to build a big class to do this. I’m just hoping other Python gurus may know some hidden language trick. Ideally I hope it can be like pointer arithmetic in C:

int lv[] = l + 3;
  • 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-16T06:42:15+00:00Added an answer on May 16, 2026 at 6:42 am

    There is no “list slice” class in the Python standard library (nor is one built-in). So, you do need a class, though it need not be big — especially if you’re content with a “readonly” and “compact” slice. E.g.:

    import collections
    
    class ROListSlice(collections.Sequence):
    
        def __init__(self, alist, start, alen):
            self.alist = alist
            self.start = start
            self.alen = alen
    
        def __len__(self):
            return self.alen
    
        def adj(self, i):
            if i<0: i += self.alen
            return i + self.start
    
        def __getitem__(self, i):
            return self.alist[self.adj(i)]
    

    This has some limitations (doesn’t support “slicing a slice”) but for most purposes might be OK.

    To make this sequence r/w you need to add __setitem__, __delitem__, and insert:

    class ListSlice(ROListSlice):
    
        def __setitem__(self, i, v):
            self.alist[self.adj(i)] = v
    
        def __delitem__(self, i, v):
            del self.alist[self.adj(i)]
            self.alen -= 1
    
        def insert(self, i, v):
            self.alist.insert(self.adj(i), v)
            self.alen += 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large list of static data from a server that i load
I have a rather large list of data that contains 5 properties per element.
I have quite a large list of words in a txt file and I'm
I have a large table with list of scores like this, one score per
I have a (derived) Menu control, that displays a rather large list of items
We have to automatically import a large list of users with some data into
So I will have a fairly large list of plot keywords in an xml
I have large data sets (10 Hz data, so 864k points per 24 Hours)
I have large batches of XHTML files that are manually updated. During the review
I'm developing a website in PHP and I have large JS files that I

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.