我需要从数组中提取整个列表。基本上我需要我的代码来打印以下内容。
a = [1, 2, 3]
b = [(1, 2, 3)]
if a != b
print "a does not equal b"
else:
print "a and b are the same!"
>>> a and b are the same!
答案 0 :(得分:1)
只需访问内部元组并转换为列表
a=[1,2,3]
b=[(1,2,3)]
bl = list(b[0])
print(a == bl) # True
答案 1 :(得分:0)
转换它:
def con(st):
res = []
for x in st:
res.append(x)
return res
所以完整的代码是:
a = [1, 2, 3]
b = [(1, 2, 3)]
def con(st):
res = []
for x in st:
res.append(x)
return res
c = con(b[0])
if a != c:
print "a does not equal b"
else:
print "a and b are the same!"
答案 2 :(得分:-1)