1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python sorted list insertion

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I need help for an exercise in python where I have to fill a preexistent code.

    The function take an integer and a sorted list, it inserts the value a and then returns the new list, I have to replace the dots by the correct answer

    It looks like this :

    def insert(a, tab):
    l = list(tab)
    l.append(a)
    i = ...
    while a < ... :
    l[i+1] = ...
    l = a
    i = ...
    return l

    >>> insert(3,[1,2,4,5])
    [1, 2, 3, 4, 5]


    Thanks for the help.

    Continue reading...

Compartilhe esta Página