Update imports
Update imports in rads_to_degrees Update imports and formatting in gcd Update imports in degrees_to_rads Update import in snake
This commit is contained in:
@ -8,10 +8,10 @@ Converts an angle from degrees to radians.
|
|||||||
Use `math.pi` and the degrees to radians formula to convert the angle from degrees to radians.
|
Use `math.pi` and the degrees to radians formula to convert the angle from degrees to radians.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
import math
|
from math import pi
|
||||||
|
|
||||||
def degrees_to_rads(deg):
|
def degrees_to_rads(deg):
|
||||||
return (deg * math.pi) / 180.0
|
return (deg * pi) / 180.0
|
||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|||||||
@ -5,16 +5,16 @@ tags: math,beginner
|
|||||||
|
|
||||||
Calculates the greatest common divisor of a list of numbers.
|
Calculates the greatest common divisor of a list of numbers.
|
||||||
|
|
||||||
Use `reduce()` and `math.gcd` over the given list.
|
Use `functools.reduce()` and `math.gcd()` over the given list.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import math
|
from math import gcd
|
||||||
|
|
||||||
def gcd(numbers):
|
def gcd(numbers):
|
||||||
return reduce(math.gcd, numbers)
|
return reduce(gcd, numbers)
|
||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
gcd([8,36,28]) # 4
|
gcd([8, 36, 28]) # 4
|
||||||
```
|
```
|
||||||
|
|||||||
@ -8,13 +8,13 @@ Converts an angle from radians to degrees.
|
|||||||
Use `math.pi` and the radian to degree formula to convert the angle from radians to degrees.
|
Use `math.pi` and the radian to degree formula to convert the angle from radians to degrees.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
import math
|
from math import pi
|
||||||
|
|
||||||
def rads_to_degrees(rad):
|
def rads_to_degrees(rad):
|
||||||
return (rad * 180.0) / math.pi
|
return (rad * 180.0) / math.pi
|
||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
import math
|
from math import pi
|
||||||
rads_to_degrees(math.pi / 2) # 90.0
|
rads_to_degrees(math.pi / 2) # 90.0
|
||||||
```
|
```
|
||||||
|
|||||||
@ -8,11 +8,12 @@ Converts a string to snake case.
|
|||||||
Break the string into words and combine them adding `_` as a separator, using a regexp.
|
Break the string into words and combine them adding `_` as a separator, using a regexp.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
import re
|
from re import sub
|
||||||
|
|
||||||
def snake(s):
|
def snake(s):
|
||||||
return '_'.join(re.sub('([A-Z][a-z]+)', r' \1',
|
return '_'.join(
|
||||||
re.sub('([A-Z]+)', r' \1',
|
sub('([A-Z][a-z]+)', r' \1',
|
||||||
|
sub('([A-Z]+)', r' \1',
|
||||||
s.replace('-', ' '))).split()).lower()
|
s.replace('-', ' '))).split()).lower()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user