Exemple #1
0
def delete_repeated_data(data: t.List) -> None:
    """Напишите код для удаления дубликатов из несортированного
    связного списка."""
    for element in data:
        if data.count(element) > 1:
            for i in range(data.count(element) - 1):
                data.pop(data.index(data.index(element) + 1, element))
Exemple #2
0
def get_table(lines: typing.List, table_name: str) -> typing.List:
    """
    Gets the given Table from OLSR data.

    :param lines:
    :param table_name:
    :return:
    """
    lines = lines[lines.index("Table: " + table_name) + 2:]
    lines = lines[:lines.index("")]
    return [line.split("\t") for line in lines]
def safe_index_of(lst: typing.List, val: typing.Any) -> int:
    """
    Finds the index of an item in a list and instead of throwing an exception returns -1 when the item DNE.
    :param lst: List to search through.
    :param val: The value to find the index of.
    :return: The index of the first value v found or -1.
    """
    try:
        return lst.index(val)
    except ValueError:
        return -1
async def save_cache_mojang_profiles(uuids: typing.List) -> None:
    for file in os.listdir(Config.TEMP_PROFILE_JSON_DIR):
        if time.time() - os.path.getmtime(
                os.path.join(Config.TEMP_PROFILE_JSON_DIR,
                             file)) < CONSIDERED_CACHED:
            uuids.pop(uuids.index(file.replace('.json', '')))
    # Age check here as well?
    async with aiohttp.ClientSession() as session:
        for uuid in uuids:
            try:
                profilejson = await get_mojang_profile(uuid, session)
                with open(
                        os.path.join(Config.TEMP_PROFILE_JSON_DIR,
                                     "{}.json".format(uuid)), 'w') as pf:
                    pf.write(json.dumps(profilejson))
            except errors.InvalidQueryError:
                return
            except errors.Non200ResponseError:
                raise
Exemple #5
0
def simple_sort(data: List[int]) -> List[list]:
    """
    Sort list of ints without using built-in methods.
    Examples:
        simple_sort([2, 9, 6, 7, 3, 2, 1])
        >>> [1, 2, 2, 3, 6, 7, 9]
    Returns:

    """
    List_copy = []
    comparison_list = []
    list5 = []
    double_number_list = []
    remove_double_val_num_list = []
    sorted_list = []
    index_sort_dict = {}

    # проверка список на ошибки значений и их перевод если это возможно

    if isinstance(List, list):
        for i in List:
            if isinstance(i, int):
                print()
            else:
                # raise ValueError("У вас ошибка в данных значений списка!")
                raise TypeError()
    # elif not isinstance(List, list):
    # for i in range(len(List)):
    # List_copy.append(i)
    # List = List_copy[:]

    # raise Exception("Ваши данные не являются списком!")
    # else:
    # raise TypeError()
    # print(List)

    # Рабочая программа
    for k in List:
        # создание списка значений с исключением проверяемого значение
        for v in List[:List.index(k)]:
            comparison_list.append(v)
        for v in List[List.index(k) + 1:]:
            comparison_list.append(v)
        # добавление дубликатов в отдельный список
        if k in comparison_list:
            if k in double_number_list:
                index = double_number_list.index(k)
                double_number_list.insert(index, k)
            else:
                double_number_list.append(k)
                remove_double_val_num_list.append(
                    k)  # добавление одного значения для дальнейшего удаления

        # print("Значение: ", k)
        # print(comparison_list)

        for v in comparison_list:
            if k < v:
                print("Число большее чем", k, "равно:", v)
                list5.append(v)
        # print("Значение ", v)
        # print("Содержит", len(list5), "значение в списке: ", list5)
        index_sort_dict[len(list5)] = k
        list5.clear()
        # Поиск максимального значения раскрыть комментарий
        """
        list6 = list5[:]
        if not list6:
            max_value = k
            print("Max: ", max_value)
        list6.clear()    
        """

        comparison_list.clear()

    # print("Всего в словаре: ", len(index_sort_dict))

    i = 0
    while i in range(len(List)):
        if i in index_sort_dict:
            sorted_list.append(index_sort_dict[i])
            print(index_sort_dict)
            print(sorted_list)
            i += 1
        else:
            i += 1

    print(sorted_list)

    # print("remove_double_val_num_list",remove_double_val_num_list)
    # print("Дупликаты: ", double_number_list)
    # удаление одного значения со списка дупликата, так как он содержится в sorted_list
    for v in remove_double_val_num_list:
        double_number_list.remove(v)

    for n in sorted_list:
        if n in double_number_list:
            double_number_list.remove(
                n)  # удаление одного значения со списка дупликата
            index = sorted_list.index(
                n
            )  # добавление одного значения со списка дупликата в sorted_list
            # print(n, "индекс которого ", index)
            sorted_list.insert(index, n)

        # else:
        # print(n)

    sorted_list = sorted_list[::-1]  # sorted_list в порядке возрастания

    return sorted_list