Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Why does starred assignment produce lists and not tuples?

In python, I can write something like this:

some_list = [(1, 2, 3), (3, 2, 1)]

for i, *args in some_list:
   print(args)

I will get the next output:

[2, 3]
[2, 1]

When we use *args as function arguments, it is unpacked into a tuple.

Why do we receive a list in this situation?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It is just a design decision. Making it a tuple was debated in the PEP 3132, but rejected on usability grounds:

Make the starred target a tuple instead of a list. This would be consistent with a function's *args, but make further processing of the result harder.

Simlarly, making it of the same type as the iterable on the rhs of the assignment, was rejected:

Try to give the starred target the same type as the source iterable, for example, b in a, *b = 'hello' would be assigned the string 'ello'. This may seem nice, but is impossible to get right consistently with all iterables.

The very example of yours is listed in the same PEP under specification.

Some reasoning is found in the mailing list of that debate.

When dealing with an iterator, you don't know the length in advance, so the only way to get a tuple would be to produce a list first and then create a tuple from it.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda