如何在Python中从数组中提取列表

如何在Python中从数组中提取列表,python,Python,我需要从数组中提取整个列表。基本上,我需要我的代码来打印以下内容 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! 只需访问内部元组并转换为列表 a=[1,2,3] b=[(1,2,3)] bl = list(b[0]) print(a == bl)

我需要从数组中提取整个列表。基本上,我需要我的代码来打印以下内容

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!

只需访问内部元组并转换为列表

a=[1,2,3]
b=[(1,2,3)]

bl = list(b[0])

print(a == bl) # True
转换它:

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!"
这个


结果>>>a和b是相同的

到目前为止,您是否尝试过做任何事情?a和b的嵌套深度如何?哪一个是数组,拉是什么意思?您是否尝试测试两个列表是否在元素方面相同?尝试将a转换为元组并比较两者。尝试将b转换为数组并比较两者。尝试将b转换为一个元组并比较两者。我想我需要写一个for循环,如果a和b的元素1相同,如果a和b的元素2相同,如果a和b的元素3相同,那么打印该消息,但idk如何做是的,对于一个写得不好的问题的解释来说,这是一个不错的答案。我认为回答如此不明确的问题没有多大意义,因为我对python还是新手。仍然不清楚列表、数组和元组之间的区别。如果元组定义为列表中的列表,语法为,,。。。数组被定义为具有语法[],然后我认为b是数组中的列表。@DevinLiner No.b是a的内部。@DevinLiner这里对列表和元组之间的差异进行了很好的讨论,leaf给了我答案,你也可以使用list代替con函数。
a = [1, 2, 3]
b = [(1, 2, 3)]

if tuple(b[0]) != a:
   print "a does not equal b"
else:
   print "a and b are the same!"