[Python] List Output Formatting

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a program that outputs multiple inputted integers in ascending order, as well as removes negative integers from said list. There's just one problem: I can type in 10 4 39 12 2, and it'll output [2, 4, 10, 12, 39]. I need a way to remove everything that isn't a number, as well as have a space come after every number. Here's what I have so far:

    numbers = [int(i) for i in input().split()] #Takes Input

    new_list = [num for num in numbers if num >= 0] #Removes Negatives

    inputs = sorted(new_list) #Sorts Input

    print(inputs) #Prints Input

    Continue reading...

Compartilhe esta Página