Finishing 11 new elements

This commit is contained in:
2020-01-08 17:32:09 +01:00
parent da0609f315
commit 1dcfd757e8
11 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
def checkio(matr):
"""return a transposed matrix"""
return map(list, zip(*matr))
if __name__ == '__main__':
assert checkio([[1, 2],
[1, 2]]) == [[1, 1],
[2, 2]], 'First'
assert checkio([[1, 0, 3, 4, 0],
[2, 0, 4, 5, 6],
[3, 4, 9, 0, 6]]) == [[1, 2, 3],
[0, 0, 4],
[3, 4, 9],
[4, 5, 0],
[0, 6, 6]], 'Second'
print('All ok')

13
PyconTW/simple_hashlib.py Normal file
View File

@@ -0,0 +1,13 @@
import hashlib
def checkio(hashed_string, algorithm):
m = hashlib.new(algorithm)
m.update(hashed_string.encode('utf-8'))
return m.hexdigest()
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio('welcome', 'md5') == '40be4e59b9a2a2b5dffb918c0e86b3d7'
assert checkio('happy spam', 'sha224') == '6e9dc3e01d57f1598c2b40ce59fc3527e698c77b15d0840ae96a8b5e'

View File

@@ -0,0 +1,22 @@
from datetime import date, timedelta
def checkio(from_date: date, to_date: date) -> int:
"""
Count the days of rest
"""
plus_a_day = timedelta(days=1)
count = 0
while from_date != to_date:
if from_date.weekday() == 5 or from_date.weekday() == 6:
count += 1
from_date += plus_a_day
count += 1 if to_date.weekday() == 5 or to_date.weekday() == 6 else 0
return count
# These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(date(2013, 9, 18), date(2013, 9, 23)) == 2, "1st example"
assert checkio(date(2013, 1, 1), date(2013, 2, 1)) == 8, "2nd example"
assert checkio(date(2013, 2, 2), date(2013, 2, 3)) == 2, "3rd example"