def unique_with_sum(arr, id_key, sum_key):
unique = {}
for n in arr:
unique.setdefault(n[id_key], { **n, sum_key: 0 })[sum_key] += n[sum_key]
return [*unique.values()]
result = unique_with_sum(arr, 'uid_1c', 'amount')
return
перед gen_nums(stop_n, number)
?def gen_nums(max_num, num):
if num <= max_num:
print(num)
gen_nums(max_num, num + 1)
# или
def gen_nums(num):
if num >= 1:
gen_nums(num - 1)
print(num)
decoded = ''.join(data_crypt.get(n, n) for n in text)
print(decoded)
from collections import Counter
def how_many_times_can_word_be_made_from_string(word, string):
count_w = Counter(word)
count_s = Counter(string)
return min(count_s[k] // v for k, v in count_w.items())
from collections import Counter
count = Counter(s)
sorted_count = sorted(count.items(), key=lambda n: n[1], reverse=True)
for n in sorted_count[:3]:
print(f'"{n[0]}" - {n[1]}')
def order_weight(string):
return { n: sum(map(int, n)) for n in string.split() }
arr = [ '3.1', '5.1', '1.3', '2.2', '13.3' ]
num = '5.666'
print('OK' if any(n.split('.')[0] == num.split('.')[0] for n in arr) else 'FUCK OFF')
grouped = {}
for n in products:
category = n['category']['name']
group = grouped.setdefault(category, {})
group[n['productId']] = { 'name': n['name'] }
from collections import Counter
item = Counter(arr).most_common(1)[0][0]