0

Let say I have a tuple like this:

a = (1, 2, 3)

I want to declare an other tuple using the tuple a and other values (4 and 5 for example) to obtain:

b = (1, 2, 3, 4, 5)

I was thinking about b = (a, 4, 5), but of course I end up with a nested tuple.

Do I have a pythonic way to do it without having to convert the tuple to a list and then making a loop?

txemsukr
  • 1,017
  • 1
  • 10
  • 32

1 Answers1

2

you can unpack all the values from a inside to the new tuple and then add your values:

b = (*a, 4, 5)
print(b)

#output: (1, 2, 3, 4, 5)

pythonic 100%

kederrac
  • 16,819
  • 6
  • 32
  • 55