[issue40022] 关于列表的基础算法问题

2020-03-20 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Test01.py runs as expected with no exceptions.  This issue appears to be based 
on a misunderstanding of one or both of two things:
a) multiplying an empty list does nothing other than returning a new empty list.
b) list.insert(index, value) treats the index as a slice index.  This is 
specified in the doc by "same as s[index:index] = [value]". (I spelled out the 
parameter names.)
https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

>>> l1, l2 = [], []
>>> l1.insert(6, 0); l2[6:6] = [0]
>>> l1, l2
([0], [0])

--
nosy: +terry.reedy
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

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



[issue40022] 关于列表的基础算法问题

2020-03-19 Thread yepan Li

New submission from yepan Li :

English is very poor so I use Chinese,
这是一个偶然的发现
lis1 = [1,2,3,4,5,6,7,8,9,10]#定义一个列表
lislen = len(lis1)#获得列表长度 此时lislen(列表1)的值为10
lis2 = []*lislen#定义一个新列表长度和第一个列表不一样但是没有元素
print(lis1)#输出测试一下第一个列表正常
for i in lis1:#用i循环遍历数组1
lis2.insert(lislen,i)#将列表2的第10(lislen)个元素设置为i(i此时为1)
lislen = lislen-lislen#将lislen(10) = 10(lislen) - 10(lislen) == 0
#下一次循环应该是lis2.insert(0,i)但是却造成了最终数组倒值的结果
print(lis2)

--
components: Windows
files: Test01.py
messages: 364648
nosy: paul.moore, steve.dower, tim.golden, yepan Li, zach.ware
priority: normal
severity: normal
status: open
title: 关于列表的基础算法问题
versions: Python 3.8
Added file: https://bugs.python.org/file48988/Test01.py

___
Python tracker 

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