Python Forum
how to refer to a subset of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to refer to a subset of a list
#1
i have a function that is given a list and it stores a special value into the first position (index 0) of that list.
def store_special_value(where_to_store):
    ...
    if isinstance(where_to_store,list):
        where_to_store[0] = special_value
    return
i want to call that function and put that value into the n-th element a list:
def main(args)
    ...
    target = []
    ...
    temp_list = [None]
    store_special_value(temp_list)
    target[n] = temp_list[0]
    ...
my question is: is there a more direct way to do this without using the temporary list? that would mean a list reference that refers to a subset of an existing list (target) but operates as if it were a whole list. list slicing creates a new list instead of referring to an existing given list, so that is not a solution. is there a way to make a subset reference like that?

i do have a real use case for this, which is more complicated, but, i prefer to work with a minimal example case, to determine a more general use solution.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
how to refer to a subset of a list - by Skaperen - Jan-15-2022, 06:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  bug in subset sum algorithm usercat123 3 1,499 Feb-07-2022, 05:41 AM
Last Post: deanhystad
  How to create subset in python? Bhavika 5 1,996 Nov-27-2021, 07:16 PM
Last Post: Gribouillis
  How to refer to particular cell GMCobraz 0 1,169 Jul-01-2020, 02:25 PM
Last Post: GMCobraz
  Grabbing a Subset of a String acemurdoc 3 2,659 Jun-18-2019, 04:57 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020