Is it possible to access the previous element generated in a list comprehension.
I am working on some toy encryption stuff. Given the key as an arbitrarily large in
You could have done this using reduce(). It's not list comprehension, but it's the functional style approach:
cipher = []
def f(previous, element):
previous = element ^ previous ^ key
cipher.append(previous)
return previous
reduce(f, message, initialization_value)
It isn't any prettier than the plain loop in this case though.