[Python] Is it possible to use (python) list comprehension in this case? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    a = []
    for b in c:
    try:
    a.append(SomeClass.SomeMethod(doc,b).Name)
    except:
    a.append(None)


    Chat GPT suggested this.. but it fails to work

    a = [ SomeClass.SomeMethod(doc,b).Name if SomeClass.SomeMethod(doc,b).Name else None for b in c]

    Continue reading...

Compartilhe esta Página