[Python] Using 'while' loops in a list comprehension

Discussão em 'Python' iniciado por Stack, Setembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    Say I have a function:

    x = []
    i = 5
    while i <= 20:
    x.append(i)
    i = i + 10
    return x


    Is there a way to convert it to a list comprehension like this?

    newList = [i=05 while i<=20 i=i+10]


    I get a syntax error.

    Continue reading...

Compartilhe esta Página