from functools import reduce
cipher = []

def f(previous, element):
    previous = element ^ previous ^ key
cipher.append(previous)
return previous
reduce(f, message, initialization_value)
Python list comprehension - access last created element?