<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>I tried to program a function, that rotates a piece of a puzzle in
the following way:</tt><tt></tt>
<p><tt>I represented a (rectangular) piece to rotate</tt><tt></tt>
<p><tt>abc
cfil</tt>
<br><tt>def ===> behk</tt>
<br><tt>ghi
adgj</tt>
<br><tt>jkl</tt><tt></tt>
<p><tt>as a list:</tt><tt></tt>
<p><tt>>>> n = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j',
'k', 'l']]</tt><tt></tt>
<p><tt>In direct mode I got:</tt><tt></tt>
<p><tt>>>> r = []</tt>
<br><tt>>>> for i in range(len(n[0])-1,-1,-1):</tt>
<br><tt> r.append(map(lambda
x: x[i],n))</tt><tt></tt>
<p><tt>>>> r</tt>
<br><tt>[['c', 'f', 'i', 'l'], ['b', 'e', 'h', 'k'], ['a', 'd', 'g', 'j']]</tt><tt></tt>
<p><tt>as intended.</tt><tt></tt>
<p><tt>If i put this into a function:</tt><tt></tt>
<p><tt>def rotate(piece):</tt>
<br><tt> r = []</tt>
<br><tt> for i in range(len(piece[0])-1,-1,-1):</tt>
<br><tt> r.append(map(lambda
x: x[i], piece))</tt>
<br><tt> return r</tt><tt></tt>
<p><tt>I get</tt><tt></tt>
<p><tt>>>> rotate(n)</tt>
<br><tt>[['a', 'd', 'g', 'j'], ['a', 'd', 'g', 'j'], ['a', 'd', 'g', 'j']]</tt>
<br><tt>>>></tt><tt></tt>
<p><tt>... as if i always had the value 0.</tt><tt></tt>
<p><tt>Why, exactly, this behaviour. Is i now taken from some other namespace?</tt>
<br><tt>If so, which one and why is it initialized with 0?</tt>
<br><tt>How can I work around this?</tt><tt></tt>
<p><tt>Thanks, Gregor Lingl</tt>
<br><tt></tt> </html>