parent
d789fc3ed8
commit
b275b0c530
5 changed files with 41 additions and 4 deletions
@ -0,0 +1,5 @@ |
|||||||
|
from datetime import datetime; |
||||||
|
|
||||||
|
date_val = datetime.utcnow() |
||||||
|
|
||||||
|
print(f'{date_val=:%Y-%m-%d}') # date_val=2021-07-09 |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
from math import ceil |
||||||
|
|
||||||
|
def chunk_into_n(lst, n): |
||||||
|
size = ceil(len(lst) / n) |
||||||
|
return list( |
||||||
|
map(lambda x: lst[x * size:x * size + size], |
||||||
|
list(range(n))) |
||||||
|
) |
||||||
|
|
||||||
|
chunk_into_n([1, 2, 3, 4, 5, 6, 7], 4) # [[1, 2], [3, 4], [5, 6], [7]] |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
a = {'max': 200} |
||||||
|
b = {'min': 100, 'max': 250} |
||||||
|
c = {'min': 50} |
||||||
|
|
||||||
|
print(a['min']) |
||||||
|
print(a['min'] + b['min'] + c['min']) # throws KeyError |
||||||
|
print(a.get('min', 0) + b.get('min', 0) + c.get('min', 0)) # 150 |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
def capitalize(s, lower_rest=False, val3=3423): |
||||||
|
return ''.join([s[:1].upper(), (s[1:].lower() if lower_rest else s[1:])]) |
||||||
|
|
||||||
|
|
||||||
|
capitalize('fooBar') # 'FooBar' |
||||||
|
capitalize('fooBar', True) # 'Foobar' |
||||||
Loading…
Reference in new issue