Python Forum
increase and decrease a slice value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
increase and decrease a slice value?
#1
say i have a list
[1,2,3,4,5,6,7]

and id like to print, 3,4,5 then 2,3,4,5,6 finally 1,2,3,4,5,6,7
using a for loop, and a slice value within its body is it possible to add to a set slice value?

as this doesn't work i will present it as pseudo code as an example to possibly better illustrate.

inv=[1,2,3,4,5,6,7]

for i in range(0,3,1):
add=(inv[3-1:4+1])

print (add)

The [3-1:4+1] being the pseudo part of the code for now as it doesn't increment on each pass. It only changes the value of the slice the one time.
Reply


Messages In This Thread
increase and decrease a slice value? - by KEYS - Nov-10-2020, 10:06 PM
RE: increase and decrease a slice value? - by KEYS - Nov-10-2020, 11:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fix pandas copy/slice warning. deanhystad 3 2,575 Sep-07-2023, 03:18 PM
Last Post: deanhystad
  Slice creates new objects? fmr300 4 3,282 Jul-20-2022, 12:34 PM
Last Post: fmr300
  InvalidIndexError: (slice(None, None, None), slice(None, -1, None)) SuperNinja3I3 1 6,561 Jul-15-2022, 05:59 AM
Last Post: Larz60+
  Increase the speed of a python loop over a pandas dataframe mcva 0 2,060 Jan-21-2022, 06:24 PM
Last Post: mcva
  How to decrease latency while recording streaming video. unicorn2019 0 1,805 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  How to increase the size of a png picture for the heatmap of the correlation? lulu43366 9 6,641 Oct-06-2021, 04:15 PM
Last Post: deanhystad
  Using SoX in Python to Increase mp3 Bitrate DRT 1 2,632 Jul-10-2021, 08:41 PM
Last Post: DRT
  How to decrease input Yankees1111 2 3,103 Apr-14-2021, 04:55 PM
Last Post: BashBedlam
  Clicker count increase by 1 each time blakefindlay 1 8,835 Feb-03-2021, 03:50 PM
Last Post: deanhystad
  Slice list Moris526 1 2,303 Dec-24-2020, 02:19 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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