class NumProcessor():
def __init__(self, length, endSymb):
self.main_buffer = []
self.search_lengt = length
self.search_endSymbol = endSymb
def addNum(self, *nums):
for num in nums:
self.main_buffer.append(num)
def sortLen(self, length, array):
for item in array:
if len(str(item)) == length:
yield item
def sortEndSymb(self, symbol, array):
for item in array:
if str(item)[-1] == str(symbol):
yield item
def sort(self):
servBufferlen = [int(i) for i in self.sortLen(self.search_lengt, self.main_buffer)]
servBufferendSym = [int(i) for i in self.sortEndSymb(self.search_endSymbol, servBufferlen)]
return min(servBufferendSym)
def insert_nums():
result = []
print('What count of numbers you want to process?\n')
n = int(input())
for i in range(n):
result.append(input())
return result
def main():
processor = NumProcessor(3, '6')
processor.addNum(*insert_nums())
result = processor.sort()
if len(result) == 0:
print('НЕ НАЙДЕНО')
else:
print(result)
if __name__ == '__main__':
main()
input()
Объяснение:
Код протестирован и работает. Копировать с сайта не нужно, ибо ломаются табуляции в коде. Вы можете ознакомиться с решением задания и попытаться повторить это самостоятельно, или попросить в комментариях меня, я залью этот код на pastebin.com и дам вам ссылку, оттуда можно спокойно будет скопировать решение. Ниже приложен скриншот оригинала кода
===== PascalABC.NET =====
begin
ReadLines('Sonet90.txt').
Where(p -> p.Length > 0).
Select(p -> p.ToUpper.MatchValues('[A-z]').
GroupBy(p -> p).Select(p -> (p.Key, p.Count)).
OrderBy(p -> -p[1]).ThenBy(p -> p[0]).First).
Foreach(p -> Writeln(p[0], ' ', p[1]))
end.
В тестовом файле с именем Sonet90.txt (он прикреплен) находится оригинал известного сонета Шекспира №90. В нем есть и пробелы, и знаки препинания и даже пустая строка.
Then hate me when thou wilt; if ever, now;
Now, while the world is bent my deeds to cross,
Join with the spite of fortune, make me bow,
And do not drop in for an after-loss:
Ah, do not, when my heart hath 'scoped this sorrow,
Come in the rearward of a conquer'd woe;
Give not a windy night a rainy morrow,
To linger out a purposed overthrow.
If thou wilt leave me, do not leave me last,
When other petty griefs have done their spite
But in the onset come; so shall I taste
At first the very worst of fortune's might,
And other strains of woe, which now seem woe,
Compared with loss of thee will not seem so.
Во втором вложении показана работа программы.