Reputation: 8147
I need to add an empty list to an existing tuple.
example:
>>> ([1],[1,2]) + ([])
([1],[1,2],[])
My problem is that python seems to evaluate ([])
to []
on which i can't use the +
operator.
I tried tuple([])
but that evaluates to ()
and nothing is added to the original tuple.
Thank you.
Upvotes: 3
Views: 643
Reputation: 5971
tuples are immutable so you need to make a new tuple
a=([1],[1,2])
b=a+([],)
Upvotes: 1
Reputation: 26586
Try
>>> ([1],[1,2])+([],)
([1], [1, 2], [])
Simply putting something in between parentheses makes it an expression. Add a comma at the end to mark it as a tuple.
Upvotes: 7