日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python深度复制列表_Python-如何深层复制列表?

發布時間:2025/3/12 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python深度复制列表_Python-如何深层复制列表? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我對列表副本有一些問題:

所以之后我得到了E0來自'get_edge',我做的副本E0通過調用'E0_copy = list(E0)'。我猜這里E0_copy是的較深的副本E0,我通過E0_copy了'karger(E)'。但是在主要功能上。

為什么'print E0[1:10]'for循環之前的結果與for循環之后的結果不同?

下面是我的代碼:

def get_graph():

f=open('kargerMinCut.txt')

G={}

for line in f:

ints = [int(x) for x in line.split()]

G[ints[0]]=ints[1:len(ints)]

return G

def get_edge(G):

E=[]

for i in range(1,201):

for v in G[i]:

if v>i:

E.append([i,v])

print id(E)

return E

def karger(E):

import random

count=200

while 1:

if count == 2:

break

edge = random.randint(0,len(E)-1)

v0=E[edge][0]

v1=E[edge][1]

E.pop(edge)

if v0 != v1:

count -= 1

i=0

while 1:

if i == len(E):

break

if E[i][0] == v1:

E[i][0] = v0

if E[i][1] == v1:

E[i][1] = v0

if E[i][0] == E[i][1]:

E.pop(i)

i-=1

i+=1

mincut=len(E)

return mincut

if __name__=="__main__":

import copy

G = get_graph()

results=[]

E0 = get_edge(G)

print E0[1:10] ## this result is not equal to print2

for k in range(1,5):

E0_copy=list(E0) ## I guess here E0_coypy is a deep copy of E0

results.append(karger(E0_copy))

#print "the result is %d" %min(results)

print E0[1:10] ## this is print2

總結

以上是生活随笔為你收集整理的python深度复制列表_Python-如何深层复制列表?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。