Latest recipes tagged "lisst" Code RecipesFinding the GCD of a list of numbers (a.k.a. Reducing numbers in a list) (Python) 2010-07-06T18:52:55-07:00Stephen Akiki <p style="color: grey"> Python recipe 577282 by <a href="/recipes/users/4172143/">Stephen Akiki</a> (<a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/denominator/">denominator</a>, <a href="/recipes/tags/gcd/">gcd</a>, <a href="/recipes/tags/greatest/">greatest</a>, <a href="/recipes/tags/lisst/">lisst</a>, <a href="/recipes/tags/reduce/">reduce</a>). </p> <p><a href="" rel="nofollow"></a></p> <p>This python code snippet allows you to find the GCD of a list of numbers, after this it is a simple matter of diving all the numbers in the list by the GCD to reduce it.</p> <p>Why this works...</p> <p>The GCD of a list of numbers [a, b, c] is GCD(GCD(a, b), c). The reduce function does exactly this and thus gives you the GCD of all the numbers in the list.</p>