Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的Append将额外的意外元素添加到计算值之间的列表中_Python_List_Loops_Append - Fatal编程技术网

Python中的Append将额外的意外元素添加到计算值之间的列表中

Python中的Append将额外的意外元素添加到计算值之间的列表中,python,list,loops,append,Python,List,Loops,Append,我正在生成一些数字,每次生成一个数字时,我都想将其存储在列表中 守则: for m in plaintexts: H = V = [] for k in xrange(0, 256): di = m[i_temp1 : i_temp2] entry = int(sBox[int(di, 16) ^ k]) print entry V.append(entry) print V H.a

我正在生成一些数字,每次生成一个数字时,我都想将其存储在列表中

守则:

for m in plaintexts:
    H = V = []

    for k in xrange(0, 256):
        di = m[i_temp1 : i_temp2]
        entry = int(sBox[int(di, 16) ^ k])
        print entry
        V.append(entry)
        print V
        H.append(bin(entry).count("1"))
    tempV.append(V)
    tempH.append(H)
不幸的是,我得到的是完全不同的:

89
[89]
250
[89, 4, 250]
240
[89, 4, 250, 6, 240]
71
[89, 4, 250, 6, 240, 4, 71]
130
[89, 4, 250, 6, 240, 4, 71, 4, 130]
202
[89, 4, 250, 6, 240, 4, 71, 4, 130, 2, 202]
125
[89, 4, 250, 6, 240, 4, 71, 4, 130, 2, 202, 4, 125]
我计算的值是相加的,但是在每个计算值之间总是加上一个随机数,这些随机值总是在2-8之间


为什么?

H
V
是同一个列表。为以下各项创建单独的列表:

H, V = [], []
H=V=[]
只创建一个列表,然后将其分配给
H
V

>>> H = V = []
>>> H is V
True
>>> H.append(42)
>>> V
[42]
>>> H, V = [], []
>>> H is V
False
>>> H.append(42)
>>> V
[]
>>> a=b=[]
>>> a.append('hello b')
>>> a,b
(['hello b'], ['hello b'])
>>> a,b=[],[]
>>> a.append('sorry b')
>>> a,b
(['sorry b'], [])