Comparing a matrix (list[][]) ?
jairodsl
jairodsl at gmail.com
Sat Jan 13 19:48:31 EST 2007
Ok, the main idea is compare each element with others elements, and go
saving the minus element positive and his position (X,Y) in the matrix,
of course min function dont let me save this position (X,Y). I dont
know if its possible do that with min function.
jDSL
Roberto Bonvallet wrote:
>
> What output are you expecting from your example matrix? If you are expecting
> it to be 5 (the smallest positive element), using "min" is the way to do it:
>
> >>> matrix = [[9, 8, 12, 15],
> ... [0, 11, 15, 18],
> ... [0, 0, 10, 13],
> ... [0, 0, 0, 5]]
> >>> min(min(x for x in row if x > 0) for row in matrix)
> 5
>
> --
> Roberto Bonvallet
More information about the Python-list
mailing list