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

182
Vistas
What is the difference between insort_left and insort_right in bisect?

Why do both insort_left and insort_right exist; isn't it always the same result since the elements are equal?

>>> import bisect
>>> foo = [1,2,3]
>>> 
>>> bisect.insort_left(foo, 1)
>>> foo
[1, 1, 2, 3]
>>> 
>>> bisect.insort_right(foo, 1)
>>> foo
[1, 1, 1, 2, 3]
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Objects can be equivalent without being identical.

>>> bisect.insort_left(foo, 1.0)
>>> foo
[1.0, 1, 1, 1, 2, 3]
>>> 
>>> bisect.insort_right(foo, 1.0)
>>> foo
[1.0, 1, 1, 1, 1.0, 2, 3]
over 4 years ago · Santiago Trujillo Denunciar

0

For most purposes the results are indistinguishable, but there are cases where it can matter, particularly when using the optional key= argument.

Do you understand the difference between sorting algorithms that are, or aren't, guaranteed to be "stable"? If not, click the link ;-)

ys = []
for x in xs:
    bisect.insort_right(ys, x)

fills ys with a stable sort of xs entries, but using insort_left() instead would not.

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