Но как защитить сам код?- как вариант, переписать бота на C/C++.
Как в telebot отправлять сообщение определенному пользователю?
Как спарсить json ответ?
Как добавить объект в список json?
Как сделать кнопку с ссылкой в telebot python?
function compoundMatch(words, target) {
const pairs = [];
for (let i = 1; i < target.length; i++) {
pairs.push([ target.slice(0, i), target.slice(i) ]);
}
for (const [ a, b ] of pairs) {
const ia = words.indexOf(a);
const ib = words.indexOf(b);
if (ia !== -1 && ib !== -1) {
return ia < ib ? [ a, b, [ ia, ib ] ] : [ b, a, [ ia, ib ] ];
}
}
return null;
}
function compoundMatch(words, target) {
const indices = {};
for (let i = 0; i < words.length; i++) {
const a = words[i];
if (!indices.hasOwnProperty(a)) {
indices[a] = i;
const b = target.replace(a, '');
if (indices.hasOwnProperty(b)) {
return [ b, a, a + b === target ? [ i, indices[b] ] : [ indices[b], i ] ];
}
}
}
return null;
}
function compoundMatch(words, target) {
const indices = {};
for (let i = 0; i < words.length; i++) {
indices[words[i]] = i;
}
for (const a in indices) {
for (const b in indices) {
if (a + b === target) {
return indices[a] < indices[b]
? [ a, b, [ indices[a], indices[b] ] ]
: [ b, a, [ indices[a], indices[b] ] ];
}
}
}
return null;
}
from operator import itemgetter
seen = set()
result = []
for dic in sorted(arr, key=itemgetter('version')):
key = (dic['category'], dic['name'])
if key in seen:
continue
result.append(dic)
seen.add(key)
print(result)
[ 1, 2 ]
, например. Или [ 5, 6, 8, 9 ]
.const range = ([...arr]) => arr
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
(n === a[i - 1] + 1) || acc.push([ n ]),
acc[acc.length - 1][1] = n,
acc
), [])
.map(([ a, b ]) => a === b ? a : `${a}-${b}`)
.join(', ');
const range = arr => ''.concat(...arr
.slice()
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
n !== a[i - 1] + 1 && acc.push(i ? `, ${n}` : n),
n === a[i - 1] + 1 && n !== a[i + 1] - 1 && acc.push(`-${n}`),
acc
), [])
);