[Python] How to use lambda expressions inside append directly

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    Apply a lambda function while appending to a list pretty much asks exactly what I want, and the solution there is fine, but I wanted to know if there was a way to directly get the result of a lambda expression appended to a list like so:

    mapset[ind].append(lambda x: str1 if str1 not in mapset[ind] else str2)


    mapset is a list
    • while str1 and str2 are strings. Is there a way for me to get the result of this lambda expression instead of its reference appended to mapset? If so how?

      I do not want to go:

      f = lambda x:...
      mapset.append(f(i))

      Continue reading...

Compartilhe esta Página