Skip to content

080_lesson#8

Open
ikrugloff wants to merge 1 commit intomasterfrom
080_lesson
Open

080_lesson#8
ikrugloff wants to merge 1 commit intomasterfrom
080_lesson

Conversation

@ikrugloff
Copy link
Owner

No description provided.

Copy link

@Dzhoker1 Dzhoker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оставил комментарии по коду

ht_with_repetitions = ''.join(random.choice(string.ascii_lowercase) for y in range(Y))
print(f'ht_with_repetitions = {ht_with_repetitions}')

class Hash:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Собственный класс для хэша - хорошо.
Но я специально написал рекомендацию по использованию готовой функции для подсчёта хэша.

return self.str[self.init:self.end]


def rabin_karp_matcher(substring, string):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Доработать алгоритм с урока - тоже хорошо.
Но задача стояла совсем другая.
Нужно анализировать строку и никакие подстроки передаваться не должны.

"""
2. Закодируйте любую строку (хотя бы из трех слов) по алгоритму Хаффмана.
"""
from heapq import heappush, heappop, heapify

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично, что вы знаете эту библиотеку )))


txt = "this is an example for huffman encoding"
symb2freq = collections.Counter(txt)
for ch in txt:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот цикл совершенно не нужен. 24 строка уже всё посчитала.

huff = encode(symb2freq)
print("Symbol\tWeight\tHuffman Code")
for p in huff:
print("%s\t\t%s\t\t%s" % (p[0], symb2freq[p[0]], p[1])) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Таблица кодирования есть.
А закодированную строку так и не вывели.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants