6
и 2
— по две. Из-за этого неопределённость среди них.>>> frequency_sort([4, 6, 2, 2, 6, 4, 2, 4, 4])
[4, 4, 4, 4, 2, 2, 2, 6, 6]
def frequency_sort(items):
return sorted(items, key=lambda v: (items.count(v), v), reverse = True)
import numpy as np
x = np.random.random((5,3,3)) * 10 // 1
array([[[8., 8., 1.],
[8., 1., 6.],
[0., 7., 7.]],
[[2., 7., 2.],
[4., 5., 1.],
[6., 8., 5.]],
[[5., 1., 1.],
[0., 1., 8.],
[5., 7., 1.]],
[[0., 5., 9.],
[6., 7., 3.],
[5., 0., 5.]],
[[0., 1., 9.],
[1., 2., 3.],
[0., 4., 7.]]])
y = x.reshape(5,9).argmax(axis=1)
# array([0, 7, 5, 2, 2])
f = lambda i: (i // 3, i % 3)
# или вернее так:
f = lambda i: (i // x.shape[1], i % x.shape[2])
(a, b) = f(y)
# array([0, 2, 1, 0, 0]), array([0, 1, 2, 2, 2])
result = np.empty((a.size + b.size,), dtype=a.dtype)
result[0::2] = a
result[1::2] = b
result.reshape(5,2)
array([[0, 0],
[2, 1],
[1, 2],
[0, 2],
[0, 2]])
df = pd.DataFrame([
[11, 'a'],
[12, 'b'],
[13, 'c'],
[13, 'd'],
[13, 'e'],
[0, 'zero'],
[1e3, 'kilo'],
]);
ids = df[0]
df[ids.isin(ids[ids.duplicated()])].sort_values(0)
0 1
2 13.0 c
3 13.0 d
4 13.0 e
df.sort_values(0).head(3)
0 1
3 0.0 zero
0 11.0 a
1 12.0 b
from itertools import combinations_with_replacement
list(combinations_with_replacement('123456', 2))
для грани_кубика_1 в диапазоне(число_граней):
для грани_кубика_2 в диапазоне(число_граней):
вывести комбинацию грань_кубика_1, грань_кубика_2
class Order:
def __init__(self, op, amount=0, price=0):
self.__op = op
self.__amount = amount
self.__price = price
@property
def price(self):
return self.__price
@price.setter
def price(self, value):
print("sending info to serverz")
self.__price = value
BUY = "buy"
SELL = "sell"
some_order = Order(SELL, amount=123, price=74.3)
some_order.price = 80.1
def loop(n):
for i in range(n):
print('Privet')
much = int(input('how much? '))
loop(much)
more = str(input('Еще? '))
if more == 'yes':
loop(much)
range()
, а лучше обойтись переменной, которую уменьшать от much
к 0:much = int(input('how much? '))
i = much
while i > 0:
print('Privet')
i = i - 1
if i == 0:
more = str(input('Еще? '))
if more == 'yes':
i = much