Files
30-seconds-of-code/snippets/gcd.md
sandy9999 df18a3f7b2 modified gcd.md to fewer lines of code
modify gcd.md to fewer lines of code

modified README
2019-04-19 14:55:34 +05:30

17 lines
326 B
Markdown

### gcd
Calculates the greatest common divisor of a list of numbers.
Uses the reduce function from the inbuilt module `functools`. Also uses the `math.gcd` function over a list.
```python
from functools import reduce
import math
def gcd(numbers):
return reduce(math.gcd, numbers)
```
``` python
gcd([8,36,28]) # 4
```