Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a tuple from array

Tags:

python

I've a list of values in an array:

 departamentos = ["Piura", "Lima"]

And I would like to transform it to:

 departamentos = (("Piura", "Piura"), ("Lima", "Lima"),)

I've tried this:

for i in departamentos:
     mis_departamentos_b  = mis_departamentos + ((i, i))

But it only returns the last item as a tuple.

mis_departamentos_b
('Lima', 'Lima')
like image 226
Omar Gonzales Avatar asked Dec 31 '25 01:12

Omar Gonzales


1 Answers

How about

tuple((x,x) for x in departamentos)

(('Piura', 'Piura'), ('Lima', 'Lima'))
like image 152
Claus Herther Avatar answered Jan 01 '26 17:01

Claus Herther