genome = 'aaaabbcaa'
cnt = 0
res = ''
for i in range(len(genome)):
newSymb = i == 0 or genome[i] != genome[i - 1]
if newSymb:
if cnt > 0: g += str(cnt)
res += genome[i]
cnt = 1
else:
cnt += 1
res += str(cnt)
print(res)
import re
str = '<tr class="img weatherIcoS"> <td class="p1"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p2 bR"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p3"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p4 bR"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p5 cur"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p6 bR"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p7"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p8"> <div class="weatherIco n300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n300.gif"/></div> </td> </tr>'
titles = re.findall(r'title="([^"]*)"', str)
print(titles) // ['Ясно', 'Ясно', 'Облачно с прояснениями', 'Облачно с прояснениями', 'Облачно с прояснениями', 'Облачно с прояснениями
, дождь', 'Облачно с прояснениями, дождь', 'Облачно с прояснениями']
import math
def middle_permutation(string):
res, letters = '', sorted(list(string))
fct = math.factorial(len(letters))
remained = math.ceil(fct / 2)
while (len(letters)):
fct /= len(letters)
cnt = math.ceil(remained/ fct) - 1
res = res + letters.pop(cnt)
remained -= fct * cnt
if (remained == 0):
remained = fct
return res
var sourceList = [11, 14, 15, 17, 27, 28, 32, 52, 53, 54, 55, 56, 57, 75, 90, 97];
sourceList.sort();
var max_d = 9, K = 4;
var result = [];
var sequence = [sourceList[0] - max_d];
sourceList.forEach(num => {
if(num - sequence[sequence.length - 1] >= max_d) {
if(sequence.length >= K) result = sequence;
sequence = [];
}
sequence.push(num);
});
if(sequence.length >= K) result = sequence;
console.log(result);