[issue43580] A Question about List Slice

2021-03-21 Thread Mark Dickinson


Change by Mark Dickinson :


--
components:  -Regular Expressions

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43580] A Question about List Slice

2021-03-21 Thread Mark Dickinson


Mark Dickinson  added the comment:

It's behaving as designed and documented; see the docs here: 
https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range 
(and particularly note 3).

In your first example, the first `-1` in `x[1:-1:-1]` is interpreted relative 
to the end of the list, so `x[1:-1:-1]` is equivalent to `x[1:9:-1]`.

`x[1::-1]` may give you what you want for the first case.

--
nosy: +mark.dickinson
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43580] A Question about List Slice

2021-03-21 Thread LittleGuy


New submission from LittleGuy <674980...@qq.com>:

# There is a question when I use list.
# If I run this following code:

x = list(range(10))
a = x[1 : -1 : -1]
print(a)

# the answer will be:
[]

# the right answer should be: [1, 0]
# But in some cases, it works well, like:

a = x[4 : 2 : -1]
print(a)

# the answer will be:
[4, 3]

# so, there may be some problems.

--
components: Regular Expressions
messages: 389220
nosy: YangS007, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: A Question about List Slice
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com