students = ['Вася', 'Петя', 'Ваня', 'Света']
present_students = ['Вася', 'Петя']
if len(students) == len(present_students):
print('Все студенты на месте. Начинаем занятие!')
else:
print('Отсутствующие к экзамену допущены не будут')
def expand(data: list):
for value in data:
if hasattr(value, '__iter__') and not isinstance(value, (str, bytes)):
yield from expand(value)
else:
yield value
data = [[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], [['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
expanded_data = []
for d in data:
expanded_data.append(list(expand(data)))
[['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], ['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
from typing import List, Iterable, Any
def super_zip(*args: Iterable) -> List[tuple]:
count = len(args)
lengths = {i: len(v) for i, v in enumerate(args)}
max_values_index = max(lengths, key=lengths.get)
def extract(chunk_index: int, value_index: int) -> Any:
try:
return args[chunk_index][value_index]
except IndexError:
return None
return [
tuple(extract(ci, vi) for ci in range(count))
for vi in range(lengths[max_values_index])
]
super_zip('abc', [1, 2, 3], ('Z', 'X', 'C'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, 'C')]
super_zip('abc', [1, 2, 3, 4], ('Z', 'X'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, None), (None, 4, None)]
super_zip('abc')
# [('a',), ('b',), ('c',)]
data.update({'bye': "godbye"})
a = [1, 2, 23, 4, 5, 6, 7, 40, 9, 10, 100, 12, 13, 14, 15, 700, 17, 18, 19, 20]
for index, group in reversed(list([(i, a[i:i+5]) for i in range(0, len(a), 5)])):
s = sum(group)
a.insert(index + 5, s)
print(f'{index} {group} => {s}')
# 15 [700, 17, 18, 19, 20] => 774
# 10 [100, 12, 13, 14, 15] => 154
# 5 [6, 7, 40, 9, 10] => 72
# 0 [1, 2, 23, 4, 5] => 35
# a
# [1, 2, 23, 4, 5, 35, 6, 7, 40, 9, 10, 72, 100, 12, 13, 14, 15, 154, 700, 17, 18, 19, 20, 774]