Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Walrus operator in list comprehensions [Python 3.8.0]

We're not mind-readers, how do you expect us to know what you tried if you don't tell us?

The walrus operator works for me:

    >>> [spam for c in "hello world" if (spam:=c.upper()) in 'AEIOU']
    ['E', 'O', 'O']

    >>> [(spam:=x**2, spam+1) for x in range(5)]
    [(0, 1), (1, 2), (4, 5), (9, 10), (16, 17)]


What did you try, and what happened?
Source by bugs.python.org #
 
PREVIOUS NEXT
Tagged: #Walrus #operator #list #comprehensions
ADD COMMENT
Topic
Name
3+9 =