[Tutor] reverse diagonal

Brian van den Broek brian.van.den.broek at gmail.com
Sun Dec 2 02:29:16 CET 2012


On 1 December 2012 20:12, Dave Angel <d at davea.name> wrote:
> On 12/01/2012 11:28 AM, Brian van den Broek wrote:
>> On 1 December 2012 10:40, richard kappler <richkappler at gmail.com> wrote:
>>> I'm working through Mark Lutz's "Python," reviewing the section on lists. I
>>> understand the list comprehension so far, but ran into a snag with the
>>> matrix. I've created the matrix M as follows:
>>>
>>> M = [[1, 2, 3[, [4, 5, 6], [7, 8, 9]]
>>>
>>> then ran through the various comprehension examples, including:
>>>
>>> diag = [M[i][i] for i in [0, 1, 2]]
>>>
>>> which, of course, gave me [1, 5, 9].
>>>
>>> Then I tried creating revdiag, wanting to return [3, 5, 7], tried several
>>> different ways, never quite got what I was looking for, so I'm looking for

<snip my answer>

> The only catch to that is it's not what he wants.  He said he wants 3, 5, 7


That does seem true. I would suggest that calling the desired function
`revdiag' invited the mistake I made. But, it is still on me for not
reading closely enough.

Best,

Brian vdB


More information about the Tutor mailing list