returning the lowest point in a list, consisting of multiple lists
def is_sink(m: List[List[int]], c: List[int]) -> bool:
lowest_point = m[0][0]
for i in range(len(m)):
for j in range(len(m)):
if m[i][j] < lowest_point:
lowest_point = m[i][j]
if c == lowest_point:
return True
else:
return False
"""
m = [[1,2,3],
[2,3,3],
[5,4,3]]
>>> is_sink(m,[0,0])
True
>>> is_sink(m,[2,2])
True
>>> is_sink(m,[3,0])
False
I'm trying to return True if c is the lowest in m. The code doesn't not print true or false
python python-3.x
 |Â
show 7 more comments
def is_sink(m: List[List[int]], c: List[int]) -> bool:
lowest_point = m[0][0]
for i in range(len(m)):
for j in range(len(m)):
if m[i][j] < lowest_point:
lowest_point = m[i][j]
if c == lowest_point:
return True
else:
return False
"""
m = [[1,2,3],
[2,3,3],
[5,4,3]]
>>> is_sink(m,[0,0])
True
>>> is_sink(m,[2,2])
True
>>> is_sink(m,[3,0])
False
I'm trying to return True if c is the lowest in m. The code doesn't not print true or false
python python-3.x
Be great if you can add a few samplem
&c
along with the result you'd expect for each.
â chris
Nov 11 at 1:23
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value inlowest_point
(which will be anint
). On the other hand,c
is a list, which meansc == lowest_point
will always beFalse
. Maybe your intent is to find the lowest inner list inm
and check whether it equals thec
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.
â FMc
Nov 11 at 1:56
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
2
@user10634542 I'm still puzzling over your examples. (A) Why shouldis_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and[2,2]
is greater than[1,2,3]
. (B) Why shouldis_sink(m,[3,0])
return true? (C) Is your intent thatc
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....
â FMc
Nov 11 at 2:42
 |Â
show 7 more comments
def is_sink(m: List[List[int]], c: List[int]) -> bool:
lowest_point = m[0][0]
for i in range(len(m)):
for j in range(len(m)):
if m[i][j] < lowest_point:
lowest_point = m[i][j]
if c == lowest_point:
return True
else:
return False
"""
m = [[1,2,3],
[2,3,3],
[5,4,3]]
>>> is_sink(m,[0,0])
True
>>> is_sink(m,[2,2])
True
>>> is_sink(m,[3,0])
False
I'm trying to return True if c is the lowest in m. The code doesn't not print true or false
python python-3.x
def is_sink(m: List[List[int]], c: List[int]) -> bool:
lowest_point = m[0][0]
for i in range(len(m)):
for j in range(len(m)):
if m[i][j] < lowest_point:
lowest_point = m[i][j]
if c == lowest_point:
return True
else:
return False
"""
m = [[1,2,3],
[2,3,3],
[5,4,3]]
>>> is_sink(m,[0,0])
True
>>> is_sink(m,[2,2])
True
>>> is_sink(m,[3,0])
False
I'm trying to return True if c is the lowest in m. The code doesn't not print true or false
python python-3.x
python python-3.x
edited Nov 11 at 2:23
asked Nov 11 at 1:12
user10634542
83
83
Be great if you can add a few samplem
&c
along with the result you'd expect for each.
â chris
Nov 11 at 1:23
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value inlowest_point
(which will be anint
). On the other hand,c
is a list, which meansc == lowest_point
will always beFalse
. Maybe your intent is to find the lowest inner list inm
and check whether it equals thec
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.
â FMc
Nov 11 at 1:56
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
2
@user10634542 I'm still puzzling over your examples. (A) Why shouldis_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and[2,2]
is greater than[1,2,3]
. (B) Why shouldis_sink(m,[3,0])
return true? (C) Is your intent thatc
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....
â FMc
Nov 11 at 2:42
 |Â
show 7 more comments
Be great if you can add a few samplem
&c
along with the result you'd expect for each.
â chris
Nov 11 at 1:23
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value inlowest_point
(which will be anint
). On the other hand,c
is a list, which meansc == lowest_point
will always beFalse
. Maybe your intent is to find the lowest inner list inm
and check whether it equals thec
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.
â FMc
Nov 11 at 1:56
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
2
@user10634542 I'm still puzzling over your examples. (A) Why shouldis_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and[2,2]
is greater than[1,2,3]
. (B) Why shouldis_sink(m,[3,0])
return true? (C) Is your intent thatc
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....
â FMc
Nov 11 at 2:42
Be great if you can add a few sample
m
& c
along with the result you'd expect for each.â chris
Nov 11 at 1:23
Be great if you can add a few sample
m
& c
along with the result you'd expect for each.â chris
Nov 11 at 1:23
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value in
lowest_point
(which will be an int
). On the other hand, c
is a list, which means c == lowest_point
will always be False
. Maybe your intent is to find the lowest inner list in m
and check whether it equals the c
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.â FMc
Nov 11 at 1:56
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value in
lowest_point
(which will be an int
). On the other hand, c
is a list, which means c == lowest_point
will always be False
. Maybe your intent is to find the lowest inner list in m
and check whether it equals the c
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.â FMc
Nov 11 at 1:56
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
2
2
@user10634542 I'm still puzzling over your examples. (A) Why should
is_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and [2,2]
is greater than [1,2,3]
. (B) Why should is_sink(m,[3,0])
return true? (C) Is your intent that c
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....â FMc
Nov 11 at 2:42
@user10634542 I'm still puzzling over your examples. (A) Why should
is_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and [2,2]
is greater than [1,2,3]
. (B) Why should is_sink(m,[3,0])
return true? (C) Is your intent that c
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....â FMc
Nov 11 at 2:42
 |Â
show 7 more comments
2 Answers
2
active
oldest
votes
The way I understand the question: (a) the c
list has 2 elements and is interpreted as indexes into the matrix m
; and (b) return true if the value specified by those indexes is the lowest value within its sublist.
def is_sink(m, c):
ci, cj = c
for i, xs in enumerate(m):
mn = min(xs)
try:
if i == ci and mn == xs[cj]:
return True
except IndexError:
pass
return False
MATRIX = [
[1, 2, 3],
[2, 3, 3],
[5, 4, 3],
]
print(is_sink(MATRIX, [0, 0])) # True
print(is_sink(MATRIX, [2, 2])) # True
print(is_sink(MATRIX, [3, 0])) # False, because out of bounds
print(is_sink(MATRIX, [1, 0])) # True
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
 |Â
show 1 more comment
Your code checks for the lowest point, not whether that point is a sink. Also, I believe this is your homework, you should not be getting help for it online. Come to my office hours.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The way I understand the question: (a) the c
list has 2 elements and is interpreted as indexes into the matrix m
; and (b) return true if the value specified by those indexes is the lowest value within its sublist.
def is_sink(m, c):
ci, cj = c
for i, xs in enumerate(m):
mn = min(xs)
try:
if i == ci and mn == xs[cj]:
return True
except IndexError:
pass
return False
MATRIX = [
[1, 2, 3],
[2, 3, 3],
[5, 4, 3],
]
print(is_sink(MATRIX, [0, 0])) # True
print(is_sink(MATRIX, [2, 2])) # True
print(is_sink(MATRIX, [3, 0])) # False, because out of bounds
print(is_sink(MATRIX, [1, 0])) # True
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
 |Â
show 1 more comment
The way I understand the question: (a) the c
list has 2 elements and is interpreted as indexes into the matrix m
; and (b) return true if the value specified by those indexes is the lowest value within its sublist.
def is_sink(m, c):
ci, cj = c
for i, xs in enumerate(m):
mn = min(xs)
try:
if i == ci and mn == xs[cj]:
return True
except IndexError:
pass
return False
MATRIX = [
[1, 2, 3],
[2, 3, 3],
[5, 4, 3],
]
print(is_sink(MATRIX, [0, 0])) # True
print(is_sink(MATRIX, [2, 2])) # True
print(is_sink(MATRIX, [3, 0])) # False, because out of bounds
print(is_sink(MATRIX, [1, 0])) # True
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
 |Â
show 1 more comment
The way I understand the question: (a) the c
list has 2 elements and is interpreted as indexes into the matrix m
; and (b) return true if the value specified by those indexes is the lowest value within its sublist.
def is_sink(m, c):
ci, cj = c
for i, xs in enumerate(m):
mn = min(xs)
try:
if i == ci and mn == xs[cj]:
return True
except IndexError:
pass
return False
MATRIX = [
[1, 2, 3],
[2, 3, 3],
[5, 4, 3],
]
print(is_sink(MATRIX, [0, 0])) # True
print(is_sink(MATRIX, [2, 2])) # True
print(is_sink(MATRIX, [3, 0])) # False, because out of bounds
print(is_sink(MATRIX, [1, 0])) # True
The way I understand the question: (a) the c
list has 2 elements and is interpreted as indexes into the matrix m
; and (b) return true if the value specified by those indexes is the lowest value within its sublist.
def is_sink(m, c):
ci, cj = c
for i, xs in enumerate(m):
mn = min(xs)
try:
if i == ci and mn == xs[cj]:
return True
except IndexError:
pass
return False
MATRIX = [
[1, 2, 3],
[2, 3, 3],
[5, 4, 3],
]
print(is_sink(MATRIX, [0, 0])) # True
print(is_sink(MATRIX, [2, 2])) # True
print(is_sink(MATRIX, [3, 0])) # False, because out of bounds
print(is_sink(MATRIX, [1, 0])) # True
edited Nov 11 at 3:04
answered Nov 11 at 1:22
FMc
32.9k1060124
32.9k1060124
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
 |Â
show 1 more comment
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
yes so if i can a function lets say by saying
â user10634542
Nov 11 at 1:24
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
>>> (m , (0,1)) it returns true or false if its bigger or the smallest
â user10634542
Nov 11 at 1:25
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
youre right, i just have one observation, your result doesnt take into the fact that, the systerm is taking in lists for m and c
â user10634542
Nov 11 at 1:32
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
hey man, so i tried your code but it returns false in every instance
â user10634542
Nov 11 at 3:04
1
1
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
I attempted to incorporate it into my larger program. Thank for your help. I will figure out the integrated aspect
â user10634542
Nov 11 at 3:18
 |Â
show 1 more comment
Your code checks for the lowest point, not whether that point is a sink. Also, I believe this is your homework, you should not be getting help for it online. Come to my office hours.
add a comment |Â
Your code checks for the lowest point, not whether that point is a sink. Also, I believe this is your homework, you should not be getting help for it online. Come to my office hours.
add a comment |Â
Your code checks for the lowest point, not whether that point is a sink. Also, I believe this is your homework, you should not be getting help for it online. Come to my office hours.
Your code checks for the lowest point, not whether that point is a sink. Also, I believe this is your homework, you should not be getting help for it online. Come to my office hours.
answered Nov 11 at 18:00
Vrbik
1
1
add a comment |Â
add a comment |Â
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244976%2freturning-the-lowest-point-in-a-list-consisting-of-multiple-lists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Be great if you can add a few sample
m
&c
along with the result you'd expect for each.â chris
Nov 11 at 1:23
I'm confused. Most of the code gives the impression that you are hunting for the lowest value in the matrix, and you are storing that value in
lowest_point
(which will be anint
). On the other hand,c
is a list, which meansc == lowest_point
will always beFalse
. Maybe your intent is to find the lowest inner list inm
and check whether it equals thec
list? You can easily clarify by providing an example or two: inputs and expected results, as suggested by @chris.â FMc
Nov 11 at 1:56
an example is >>> m = [[1,2,3]
â user10634542
Nov 11 at 1:59
/n [2,3,3]/n[5,4,3]]
â user10634542
Nov 11 at 2:00
2
@user10634542 I'm still puzzling over your examples. (A) Why should
is_sink(m,[2,2])
return true? The lowest value in the matrix is 1, not 2, and[2,2]
is greater than[1,2,3]
. (B) Why shouldis_sink(m,[3,0])
return true? (C) Is your intent thatc
always have 2 elements (like your examples); if so why? Maybe that will provide a clue....â FMc
Nov 11 at 2:42