#programming #language #python #special
Walrus operator is a special case of listcomp when you need to store the last element of the list.
x = 'ABC'
codes = [last := ord(c) for c in x]
# last will be 67
#programming #language #python #special
Walrus operator is a special case of listcomp when you need to store the last element of the list.
x = 'ABC'
codes = [last := ord(c) for c in x]
# last will be 67
listcomp
create a new list, so it is necessary to allocate a whole list to manipulate a listcomp
. There is a special case known as Walrus operator.
=
, however, it is not recommended