Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda