🚚 Move file like in checkio

This commit is contained in:
2021-07-28 15:54:44 +02:00
parent 8d993a5bcd
commit f5059f11d1
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
def group_equal(els):
result = []
current = []
for element in els:
if len(current) == 0 or element in current:
current.append(element)
else:
result.append(current)
current = [element]
if len(current) != 0:
result.append(current)
return result
if __name__ == '__main__':
print("Example:")
print(group_equal([1, 1, 4, 4, 4, "hello", "hello", 4]))
# These "asserts" are used for self-checking and not for an auto-testing
assert group_equal([1, 1, 4, 4, 4, "hello", "hello", 4]) == [[1, 1], [4, 4, 4], ["hello", "hello"], [4]]
assert group_equal([1, 2, 3, 4]) == [[1], [2], [3], [4]]
assert group_equal([1]) == [[1]]
assert group_equal([]) == []
print("Coding complete? Click 'Check' to earn cool rewards!")

View File

@@ -0,0 +1,28 @@
def checkio(matr):
clone = zip(*matr)
modifiedClone = []
for row in clone:
modifiedClone.append(list(map(mult, row)))
for i, row in enumerate(matr):
for j, cell in enumerate(matr[i]):
if cell != modifiedClone[i][j]:
return False
return True
def mult(e):
return -1 * e
if __name__ == '__main__':
assert checkio([[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]) == True, 'First'
assert checkio([[0, 1, 2],
[-1, 1, 1],
[-2, -1, 0]]) == False, 'Second'
assert checkio([[0, 1, 2],
[-1, 0, 1],
[-3, -1, 0]]) == False, 'Third'
print('All ok')