Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass Tuple as a Slice
#1
I'd like to pass a tuple (2, 3) as a parameter value into a function (via array variable below), so that it replaces the slice value 2:3 in the third line. What would be the easiest way to achieve that?

def function(object, array, slices):
    selections = ... object ... 
    for i, selection in enumerate(selections[2:3]): # <= array variable replaces 2:3
        for x, y in slices:
            slur(object[x : y])

object = ...
tupleIndice = (2, 3)
tupleSlices = (0, 3), (3, 5)

function(staff, tupleIndice, tupleSlices)
My apology if this may not be the right place to ask this question. Thank you for your time and suggestion!
Reply


Messages In This Thread
Pass Tuple as a Slice - by nagymusic - Dec-11-2019, 10:47 PM
RE: Pass Tuple as a Slice - by ichabod801 - Dec-11-2019, 11:17 PM
RE: Pass Tuple as a Slice - by nagymusic - Dec-12-2019, 04:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fix pandas copy/slice warning. deanhystad 3 885 Sep-07-2023, 03:18 PM
Last Post: deanhystad
  How to pass encrypted pass to pyodbc script tester_V 0 905 Jul-27-2023, 12:40 AM
Last Post: tester_V
  Slice creates new objects? fmr300 4 1,360 Jul-20-2022, 12:34 PM
Last Post: fmr300
  InvalidIndexError: (slice(None, None, None), slice(None, -1, None)) SuperNinja3I3 1 4,518 Jul-15-2022, 05:59 AM
Last Post: Larz60+
  Slice list Moris526 1 1,676 Dec-24-2020, 02:19 AM
Last Post: deanhystad
  increase and decrease a slice value? KEYS 2 2,140 Nov-10-2020, 11:35 PM
Last Post: KEYS
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,890 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,593 Sep-07-2020, 08:02 AM
Last Post: perfringo
  Preferred way to slice a list SvetlanaofVodianova 3 2,585 Dec-09-2019, 11:50 PM
Last Post: SvetlanaofVodianova
  Pass by reference vs Pass by value leodavinci1990 1 2,236 Nov-20-2019, 02:05 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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