I am trying to add a tuple of a (number, (tuple)), but it drops the outer tuple.
How do I change the code so that l1 comes out looking like L2? It appears to drop the outer tuple and convert it to list elements? How do I stop that? Better yet, why is it happening?
l1 = []
t1 = (1.0 , (2.0,3.0))
l1.extend((t1))
t2 = (4.0 , (5.0,6.0))
l1.extend(t2)
print(l1)
l2 = [(1.0, (2.0,3.0)),
(4.0, (5.0,6.0))]
print(l2)
l1 comes out as [1.0, (2.0, 3.0), 4.0, (5.0, 6.0)]
l2 comes out as [(1.0, (2.0, 3.0)), (4.0, (5.0, 6.0))]
Use append:
l1 = []
t1 = (1.0, (2.0, 3.0))
l1.append((t1))
t2 = (4.0, (5.0, 6.0))
l1.append(t2)
print(l1)
l2 = [(1.0, (2.0, 3.0)),
(4.0, (5.0, 6.0))]
print(l2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With