lesson 3,4
This commit is contained in:
parent
97aba26e92
commit
8ce58831aa
33
guess.py
Normal file
33
guess.py
Normal file
@ -0,0 +1,33 @@
|
||||
import itertools
|
||||
|
||||
def all_combinations(alphabet, max_length):
|
||||
"""Генерирует все комбинации длиной от 1 до max_length"""
|
||||
all_combos = []
|
||||
for length in range(1, max_length + 1):
|
||||
combos = itertools.product(alphabet, repeat=length)
|
||||
all_combos.extend([''.join(combo) for combo in combos])
|
||||
return all_combos
|
||||
|
||||
russian_lower = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
|
||||
def vectorize(word, combinations):
|
||||
vector = []
|
||||
if len(word) == 1:
|
||||
return None
|
||||
last = None
|
||||
for curr in word:
|
||||
if not last:
|
||||
last = curr
|
||||
continue
|
||||
pair = last + curr
|
||||
indx = combinations.index(pair)
|
||||
vector.append(indx)
|
||||
return vector
|
||||
|
||||
|
||||
word = 'маме'
|
||||
combinations = all_combinations(russian_lower, 2)
|
||||
result = vectorize(word, combinations)
|
||||
|
||||
print("Все комбинации длиной 1-2:")
|
||||
print(combinations)
|
||||
print("Вектор:", result)
|
||||
BIN
lesson_2/home_task/color.jpg
Normal file
BIN
lesson_2/home_task/color.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
BIN
lesson_3/manual/lection_3.pdf
Normal file
BIN
lesson_3/manual/lection_3.pdf
Normal file
Binary file not shown.
BIN
lesson_4/manual/collection.pdf
Normal file
BIN
lesson_4/manual/collection.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user