E
Найти все нули в списке и убрать их в конец списка
А где нули то потерял?)
array += [array.pop(i)]
Size: a a a
E
Найти все нули в списке и убрать их в конец списка
array += [array.pop(i)]
АА
array += [array.pop(i)]
E
АА
E
АА
А
res = [i for i in arr if not (i == 0 and not isinstance(i, bool))]
res += [0] * (len(arr) - len(res))
АА
res = [i for i in arr if not (i == 0 and not isinstance(i, bool))]
res += [0] * (len(arr) - len(res))
K
АА
res = [i for i in arr if not (i == 0 and not isinstance(i, bool))]
res += [0] * (len(arr) - len(res))
𝕬
Найти все нули в списке и убрать их в конец списка
count = array.count(0)
array.remove(0)
array.extend([0 for _ in range(count)])
E
python3
array = [0, 'a', 1, None, "string", False, "string", 1, 0]
for i, el in enumerate(array):
if el in (0, 0.0) and not isinstance(el, bool):
array += [array.pop(i)]
print(array)
['a', 1, None, 'string', False, 'string', 1, 0, 0]
А
count = array.count(0)
array.remove(0)
array.extend([0 for _ in range(count)])
E
python3
array = [0, 'a', 1, None, "string", False, "string", 1, 0]
for i, el in enumerate(array):
if el in (0, 0.0) and not isinstance(el, bool):
array += [array.pop(i)]
print(array)
['a', 1, None, 'string', False, 'string', 1, 0, 0]
𝕬
А
АА
А
sorted(array, key=lambda x: x==0 and not isinstance(x, bool))
АА
sorted(array, key=lambda x: x==0 and not isinstance(x, bool))
R3
res = [i for i in arr if not (i == 0 and not isinstance(i, bool))]
res += [0] * (len(arr) - len(res))