Jeremy Bowers <[EMAIL PROTECTED]> writes:
On Tue, 08 Feb 2005 17:36:19 +0100, Bernhard Herzog wrote:
Nick Vargish <[EMAIL PROTECTED]> writes:
"Xah Lee" <[EMAIL PROTECTED]> writes:
is it possible to write python code without any indentation?
Not if Turing-completeness is something you desire.
Bernhard Herzog wrote: .... a Turing Machine in one line plus assignments - nice! Turns out that pypy is more verbose than strictly necessary ;-) ...
BTW, I realized that it is indeed possible for a LC to maintain its own state without being passed an external mutable. The trick is to use itertools.repeat to return the same mutable object on each iteration.
So, here's factorial in one line: # state refers to list of state history - it is initialized to [1] # on any iteration, the previous state is in state[-1] # the expression also uses the trick of list.append() => None # to both update the state, and return the last state
>>> [state.append(state[-1] * symbol) or state[-1] ... for symbol, state in it.izip(range(1,10),it.repeat([1])) ... ] [1, 2, 6, 24, 120, 720, 5040, 40320, 362880] >>>
Now, who was claiming that 'reduce' was opaque?
Michael ;-)
-- http://mail.python.org/mailman/listinfo/python-list