I need to pull an entire list out of an array. Essentially what I need my code to print the following.
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!
I need to pull an entire list out of an array. Essentially what I need my code to print the following.
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!
Just access the inner tuple and convert to list
a=[1,2,3]
b=[(1,2,3)]
bl = list(b[0])
print(a == bl) # True
Converting it:
def con(st):
res = []
for x in st:
res.append(x)
return res
So the full code would be:
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!"
The user leaf gave me the answer.
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!"
Result >>> a and b are the same!