On Sun, Dec 2, 2012 at 2:32 AM, Steven D'Aprano wrote:
>
>> ~i returns the value (-i - 1):
>
> Assuming certain implementation details about how integers are stored,
> namely that they are two-compliment rather than one-compliment or
> something more exotic.
Yes, the result is platform dependent,
On Sat, Dec 01, 2012 at 09:19:57PM -0500, eryksun wrote:
> On Sat, Dec 1, 2012 at 11:31 AM, Dave Angel wrote:
> >
> > revdiag = [M[i][len(M)-1-i] for i in range(len(M)) ]
>
> You might sometimes see this using the bitwise invert operator ~ (i.e.
> __invert__, operator.invert):
>
> >>> M = [
On 12/01/2012 09:55 PM, eryksun wrote:
> On Sat, Dec 1, 2012 at 9:35 PM, Dave Angel wrote:
>>
>> [M[i][~i] for i,dummy in enumerate(M) ]
>
> Since enumerate() iterates the rows, you could skip the first index:
>
> >>> [row[~i] for i,row in enumerate(M)]
> [3, 5, 7]
>
>
Great job. And
On Sat, Dec 1, 2012 at 9:35 PM, Dave Angel wrote:
>
> [M[i][~i] for i,dummy in enumerate(M) ]
Since enumerate() iterates the rows, you could skip the first index:
>>> [row[~i] for i,row in enumerate(M)]
[3, 5, 7]
___
Tutor maillist - Tutor@py
On 12/01/2012 09:19 PM, eryksun wrote:
> On Sat, Dec 1, 2012 at 11:31 AM, Dave Angel wrote:
>>
>> revdiag = [M[i][len(M)-1-i] for i in range(len(M)) ]
>
> You might sometimes see this using the bitwise invert operator ~ (i.e.
> __invert__, operator.invert):
>
> >>> M = [[1, 2, 3], [4, 5, 6]
On Sat, Dec 1, 2012 at 11:31 AM, Dave Angel wrote:
>
> revdiag = [M[i][len(M)-1-i] for i in range(len(M)) ]
You might sometimes see this using the bitwise invert operator ~ (i.e.
__invert__, operator.invert):
>>> M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> [M[i][~i] for i in xrange(len(M
On 1 December 2012 20:12, Dave Angel wrote:
> On 12/01/2012 11:28 AM, Brian van den Broek wrote:
>> On 1 December 2012 10:40, richard kappler 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 wi
On 12/01/2012 11:28 AM, Brian van den Broek wrote:
> On 1 December 2012 10:40, richard kappler 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 fol
On 1 December 2012 10:40, richard kappler 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
On 12/01/2012 10:40 AM, richard kappler 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]]
There's an
On Sat, Dec 1, 2012 at 9:40 AM, richard kappler 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]]
>
>>> revdiag = [M[i][i] for i in [2, 1, 0]]
>>> revdiag
[9, 5, 1]
The reverse diag entries (that you are seeking to get) are not correct.
They should be M[0][2], M[1][1], M[2][0].
So the code could be --
revdiag = []
for i in [0, 1, 2]:
j = 2 - i
revdiag.append( M[i][j] )
I hope it helps.
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:
d
13 matches
Mail list logo