returning the lowest point in a list, consisting of multiple lists










-1














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










share|improve this question























  • 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










  • 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 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















-1














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










share|improve this question























  • 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










  • 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 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













-1












-1








-1


1





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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 2:23

























asked Nov 11 at 1:12









user10634542

83




83











  • 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










  • 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 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
















  • 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










  • 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 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















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












2 Answers
2






active

oldest

votes


















0














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





share|improve this answer






















  • 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


















0














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.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    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

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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





    share|improve this answer






















    • 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















    0














    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





    share|improve this answer






















    • 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













    0












    0








    0






    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





    share|improve this answer














    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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
















    • 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













    0














    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.






    share|improve this answer

























      0














      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.






      share|improve this answer























        0












        0








        0






        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 18:00









        Vrbik

        1




        1



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線