N

array = [1111111111, '0000000000', 1111100000, '0011001100', 1010101, '0011', 1100, '', 1, 0, 1100111000, 1110101110, 1101110000, 1101010010, 1110011100, 1001101000]
def weather_ratio(period):
series_sunny = [len(i) for i in period.split('0') if i]
series_rainy = [len(i) for i in period.split('1') if i]
ratio_sunny = ratio_rainy = 0
if series_sunny:
ratio_sunny = sum(series_sunny)/len(series_sunny)
if series_rainy:
ratio_rainy = sum(series_rainy)/len(series_rainy)
return round(ratio_sunny, 1), round(ratio_rainy, 1)
for a in array:
r, s = weather_ratio(str(a))
print(f'{a:<10} -> rainy: {r:4}, sunny: {s}')
He'll take it out:1111111111 -> rainy: 10.0, sunny: 0
0000000000 -> rainy: 0, sunny: 10.0
1111100000 -> rainy: 5.0, sunny: 5.0
0011001100 -> rainy: 2.0, sunny: 2.0
1010101 -> rainy: 1.0, sunny: 1.0
0011 -> rainy: 2.0, sunny: 2.0
1100 -> rainy: 2.0, sunny: 2.0
-> rainy: 0, sunny: 0
1 -> rainy: 1.0, sunny: 0
0 -> rainy: 0, sunny: 1.0
1100111000 -> rainy: 2.5, sunny: 2.5
1110101110 -> rainy: 2.3, sunny: 1.0
1101110000 -> rainy: 2.5, sunny: 2.5
1101010010 -> rainy: 1.2, sunny: 1.2
1110011100 -> rainy: 3.0, sunny: 2.0
1001101000 -> rainy: 1.3, sunny: 2.0
If you split a strict representation of the number by some divider (period = '1100111000' by '0', for example), then the split() will return the sequence of opposite values: ['11', '', '111', '', '', '']♪ By choosing the non-desert and by dividing their length by number, we shall receive the average duration of the continuous periods. ♪ ♪