JustCaptain kod-buduschego
c70a58f596a8dfc2ab4b734e1775d88fdefe87b3
Перейти к файлу
Код
task_1.py
def solve(strings: list[str]) -> list[list[str]]:
    result: list[list[str]] = []
    values: dict[tuple, int] = {}
    count: int = 1

    if len(strings) == 0:
        return result
    for string in strings:
        parse: tuple = tuple(sorted(list(string)))
        print(values, parse)
        if values.get(parse):  # if 0 => if False
            result[values[parse] - 1].append(string)
        else:
            values[parse] = count
            result.append([string])
            count += 1
    return result


x = solve(strings=["ток", "кот", "окт", "ток", "топ", "топ", "пот"])
print(x)