Update formatting
This commit is contained in:
@ -7,7 +7,7 @@ lastUpdated: 2020-11-02T19:27:07+02:00
|
|||||||
|
|
||||||
Returns the length of a string in bytes.
|
Returns the length of a string in bytes.
|
||||||
|
|
||||||
- Use `str.encode('utf-8')` to encode the given string and return its length.
|
- Use `str.encode()` to encode the given string and return its length.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def byte_size(s):
|
def byte_size(s):
|
||||||
|
|||||||
@ -9,7 +9,7 @@ Creates a list of dates between `start` (inclusive) and `end` (not inclusive).
|
|||||||
|
|
||||||
- Use `datetime.timedelta.days` to get the days between `start` and `end`.
|
- Use `datetime.timedelta.days` to get the days between `start` and `end`.
|
||||||
- Use `int()` to convert the result to an integer and `range()` to iterate over each day.
|
- Use `int()` to convert the result to an integer and `range()` to iterate over each day.
|
||||||
- Use a list comprehension and `datetime.timedelta()` to create a list of `datetime.date` objects.
|
- Use a list comprehension and `datetime.timedelta` to create a list of `datetime.date` objects.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
from datetime import timedelta, date
|
from datetime import timedelta, date
|
||||||
|
|||||||
@ -8,11 +8,11 @@ lastUpdated: 2021-01-04T12:47:04+02:00
|
|||||||
|
|
||||||
Converts Fahrenheit to Celsius.
|
Converts Fahrenheit to Celsius.
|
||||||
|
|
||||||
- Follow the conversion formula `C = (F - 32) * 5/9`.
|
- Follow the conversion formula `C = (F - 32) * 5 / 9`.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def fahrenheit_to_celsius(degrees):
|
def fahrenheit_to_celsius(degrees):
|
||||||
return ((degrees - 32) * 5/9)
|
return ((degrees - 32) * 5 / 9)
|
||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-11-02T19:27:53+02:00
|
|||||||
|
|
||||||
Creates a dictionary with the unique values of a list as keys and their frequencies as the values.
|
Creates a dictionary with the unique values of a list as keys and their frequencies as the values.
|
||||||
|
|
||||||
- Use `collections.defaultdict()` to store the frequencies of each unique element.
|
- Use `collections.defaultdict` to store the frequencies of each unique element.
|
||||||
- Use `dict()` to return a dictionary with the unique elements of the list as keys and their frequencies as the values.
|
- Use `dict()` to return a dictionary with the unique elements of the list as keys and their frequencies as the values.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
---
|
---
|
||||||
title: lcm
|
title: lcm
|
||||||
tags: math,list,intermediate
|
tags: math,list,intermediate
|
||||||
firstSeen: 2018-01-08T22:30:17+02:00
|
firstSeen: 2018-01-08T22:30:17+02:00
|
||||||
lastUpdated: 2020-11-02T19:31:15+02:00
|
lastUpdated: 2020-11-02T19:31:15+02:00
|
||||||
---
|
---
|
||||||
|
|
||||||
Returns the least common multiple of a list of numbers.
|
Returns the least common multiple of a list of numbers.
|
||||||
|
|
||||||
- Use `functools.reduce()`, `math.gcd()` and `lcm(x,y) = x * y / gcd(x,y)` over the given list.
|
- Use `functools.reduce()`, `math.gcd()` and `lcm(x, y) = x * y / gcd(x, y)` over the given list.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|||||||
@ -5,9 +5,9 @@ firstSeen: 2020-01-02T20:25:45+02:00
|
|||||||
lastUpdated: 2020-11-09T23:56:11+02:00
|
lastUpdated: 2020-11-09T23:56:11+02:00
|
||||||
---
|
---
|
||||||
|
|
||||||
Tests a value, `x`, against a testing function, conditionally applying a function.
|
Tests a value, `x`, against a testing function, conditionally applying a function.
|
||||||
|
|
||||||
- Check if the value of `predicate(x)` is `True` and if so return `when_true(x)`, otherwise return `x`.
|
- Check if the value of `predicate()` is `True` for `x` and if so call `when_true()`, otherwise return `x`.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def when(predicate, when_true):
|
def when(predicate, when_true):
|
||||||
|
|||||||
Reference in New Issue
Block a user