From 51a9a4a149afef6f43d13e07812fd3e062b2d58a Mon Sep 17 00:00:00 2001 From: Yesen Date: Thu, 5 Oct 2023 14:42:05 +0300 Subject: [PATCH] update --- .../beneficial_features/dictionaries.py | 0 .../dictionaries_and_lists.py | 30 +++++++++ practica/stepik/beneficial_features/double.py | 24 +++++++ .../stepik/beneficial_features/indentation.py | 13 +++- practica/stepik/beneficial_features/input.py | 5 +- practica/stepik/sketches/sketches.py | 13 +--- .../stepik/stepik_tasks/sum_num_nearby.py | 62 +++++++++---------- 7 files changed, 102 insertions(+), 45 deletions(-) delete mode 100644 practica/stepik/beneficial_features/dictionaries.py create mode 100644 practica/stepik/beneficial_features/dictionaries_and_lists.py create mode 100644 practica/stepik/beneficial_features/double.py diff --git a/practica/stepik/beneficial_features/dictionaries.py b/practica/stepik/beneficial_features/dictionaries.py deleted file mode 100644 index e69de29..0000000 diff --git a/practica/stepik/beneficial_features/dictionaries_and_lists.py b/practica/stepik/beneficial_features/dictionaries_and_lists.py new file mode 100644 index 0000000..3e4c04b --- /dev/null +++ b/practica/stepik/beneficial_features/dictionaries_and_lists.py @@ -0,0 +1,30 @@ +# students = ['Ivan', 'Masha', 'Sasha'] +# students += ['Olga'] +# students += 'Olga' +# print (students) + +# a = [1, 2, 3] +# b = a +# print (b) +# a[1] = 10 +# print (b) +# b[0] = 20 +# print (b) +# print (a) +# a = [5, 6] +# print (b) +# print (a) + +# # переделать в список каждую отдельную цифру +# num = 1234 +# lst = [int(i) for i in str(num)] + +# # наоборот из списка в набор слов через пробел +# b = ("apple", "banana", "cherry") +# print (" ".join(b)) + + +n =3 +a = [[0]*n]*n +a[0][0]= 5 +print (a) \ No newline at end of file diff --git a/practica/stepik/beneficial_features/double.py b/practica/stepik/beneficial_features/double.py new file mode 100644 index 0000000..1ffe35c --- /dev/null +++ b/practica/stepik/beneficial_features/double.py @@ -0,0 +1,24 @@ +# нахождение дубликатов и вывод уникальных элементов +a = input().split() +a2 = [] +for item in a: + c = a.count(item) + if c > 1: + a2.append(item) + if c == 1: + None +def del_dubl(a2): + seen = set() + seen_add = seen.add + return [x for x in a2 if not (x in seen or seen_add(x))] +for i in del_dubl(a2): + print(i, end=' ') + + + # удаление дубликатов и вывод уникальных в виде списка +a = input().split() +def del_dubl(a): + seen = set() + seen_add = seen.add + return [x for x in a if not (x in seen or seen_add(x))] +print (del_dubl(a)) \ No newline at end of file diff --git a/practica/stepik/beneficial_features/indentation.py b/practica/stepik/beneficial_features/indentation.py index 50f9cfe..6ed9782 100644 --- a/practica/stepik/beneficial_features/indentation.py +++ b/practica/stepik/beneficial_features/indentation.py @@ -5,4 +5,15 @@ # print ("\t",str(num), sep='\t') # num = 12 -# print("\t" + str(num), end="") \ No newline at end of file +# print("\t" + str(num), end="") + +# for j in range(1): +# print ("c", end="v") + +# a = 1 +# m=2 +# n=3 +# print (a+ m,n,end ="\t") + +# for i in range(c, d + 1): +# print("\t" + str(i), end="") \ No newline at end of file diff --git a/practica/stepik/beneficial_features/input.py b/practica/stepik/beneficial_features/input.py index 84b6d41..1561d68 100644 --- a/practica/stepik/beneficial_features/input.py +++ b/practica/stepik/beneficial_features/input.py @@ -1,2 +1,5 @@ -a, b, c, d = int(input()), int(input()), int(input()), int(input()) +# построчный инпут записанный в 1 строку +# a, b, c, d = int(input()), int(input()), int(input()), int(input()) + + diff --git a/practica/stepik/sketches/sketches.py b/practica/stepik/sketches/sketches.py index 008995a..2fe60c5 100644 --- a/practica/stepik/sketches/sketches.py +++ b/practica/stepik/sketches/sketches.py @@ -35,15 +35,4 @@ # print() -initial_list = input().split() -sum_list = [] -left_index = -1 -right_index = -len(initial_list) + 1 -middle_index = 0 -while middle_index < len(initial_list): - sum_list.append(initial_list[left_index] + initial_list[right_index]) - left_index += 1 - right_index += 1 - middle_index += 1 -print(sum_list) - \ No newline at end of file + \ No newline at end of file diff --git a/practica/stepik/stepik_tasks/sum_num_nearby.py b/practica/stepik/stepik_tasks/sum_num_nearby.py index 41e4f6a..5ad4b6f 100644 --- a/practica/stepik/stepik_tasks/sum_num_nearby.py +++ b/practica/stepik/stepik_tasks/sum_num_nearby.py @@ -1,38 +1,38 @@ # вариант решения 1 -# a = input().split() -# len_a = len(a) - 1 -# for index, number in enumerate(a): -# if len_a == 0: -# print (number) -# else: -# if index == 0: -# S = int(a[-1]) + int(a[1]) -# b = str(S) -# elif index != 0 and index != int(len_a) : -# n_index_0 = int(int(a.index(number)) + 1) -# n_index_2 = int(int(a.index(number)) - 1) -# n_0 = a[n_index_0] -# N_2 = a[n_index_2] -# S1 = int(n_0) + int(N_2) -# b += " " + str(S1) -# elif index == int(len_a): -# S2 = int(a[0]) + int(a[-2]) -# b += " " + str(S2) -# print (b) +a = input().split() +len_a = len(a) - 1 +for index, number in enumerate(a): + if len_a == 0: + print (number) + else: + if index == 0: + S = int(a[-1]) + int(a[1]) + b = str(S) + elif index != 0 and index != int(len_a) : + n_index_0 = int(int(a.index(number)) + 1) + n_index_2 = int(int(a.index(number)) - 1) + n_0 = a[n_index_0] + N_2 = a[n_index_2] + S1 = int(n_0) + int(N_2) + b += " " + str(S1) + elif index == int(len_a): + S2 = int(a[0]) + int(a[-2]) + b += " " + str(S2) + print (b) # вариант решения 2 -короче -# initial_list = input().split() -# sum_list = [] -# left_index = -1 -# right_index = -len(initial_list) + 1 -# middle_index = 0 -# while middle_index < len(initial_list): -# sum_list.append(initial_list[left_index] + initial_list[right_index]) -# left_index += 1 -# right_index += 1 -# middle_index += 1 -# print(sum_list) +initial_list = input().split() +sum_list = [] +left_index = -1 +right_index = -len(initial_list) + 1 +middle_index = 0 +while middle_index < len(initial_list): + sum_list.append(initial_list[left_index] + initial_list[right_index]) + left_index += 1 + right_index += 1 + middle_index += 1 +print(sum_list) # вариант решения 3 a = [int(item) for item in input().split()]