{"id":421,"date":"2021-03-16T15:59:05","date_gmt":"2021-03-16T15:59:05","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/?page_id=420"},"modified":"2021-06-24T09:24:19","modified_gmt":"2021-06-24T08:24:19","slug":"find-max-min","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/higher\/find-max-min\/","title":{"rendered":"Find Maximum\/Minimum"},"content":{"rendered":"<p>Search through a list of values, looking for either:<\/p>\n<ul>\n<li>the largest\/smallest value, or<\/li>\n<li>the location (index) of the largest\/smallest value<\/li>\n<\/ul>\n<h1>General Algorithms<\/h1>\n<p><em>Algorithms for finding the minimum are the same, but replacing &#8220;&gt;&#8221; with &#8220;&lt;&#8220;, and a change in the variable names.<\/em><\/p>\n<h2>Find largest value<\/h2>\n<pre>max = first item in list\nfor index = rest of list\n    if list[index] &gt; max then\n        max = list[index]\n    end if\nnext item<\/pre>\n<h2>Find index of largest value<\/h2>\n<pre>max = 0\nfor index = remaining items in list\n    if list[index] &gt; list[max] then\n        max = index\n    end if\nnext item<\/pre>\n<h1>Examples<\/h1>\n<h2>Find largest value<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\ntallestHeight = heights&#x5B;0]\r\n \r\nfor mountain in range(1,len(heights)):\r\n \r\n    if heights&#x5B;mountain] &gt; tallestHeight:\r\n        tallestHeight = heights&#x5B;mountain]\r\n \r\nprint(f&quot;Tallest height = {tallestHeight }&quot;)\r\n# <\/pre>\n<h2>Find index of largest value<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\ntallest = 0\r\n \r\nfor mountain in range(1,len(heights)):\r\n \r\n    if heights&#x5B;mountain] &gt; heights&#x5B;tallest]:\r\n        tallest = mountain\r\n \r\nprint(f&quot;The tallest mountain is {names&#x5B;tallest]}&quot;)\r\n#\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Search through a list of values, looking for either: the largest\/smallest value, or the location (index) of the largest\/smallest value General Algorithms Algorithms for finding the minimum are the same, but replacing &#8220;&gt;&#8221; with &#8220;&lt;&#8220;, and a change in the variable names. Find largest value max = first item in list for index = rest of list if list[index] &gt; max then max = list[index] end if next item Find<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/higher\/find-max-min\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":330,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-421","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/comments?post=421"}],"version-history":[{"count":6,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/421\/revisions"}],"predecessor-version":[{"id":664,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/421\/revisions\/664"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/330"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/media?parent=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}