<jupyter_start><jupyter_text><NAME> (Б03-907, семинар 07.09.2020)  problem 1<jupyter_code>import numpy as np
def maxim(seq:list):
    maxim = seq[0]
    for i in range(len(seq)):
        if seq[i] > maxim:
            maxim = seq[i]
    return maxim       
def minim(seq:list):
    minim = seq[0]
    for i in range(len(seq)):
        if seq[i] < minim:
            minim = seq[i]
    return minim
def mean(seq:list):
    seq = np.array(seq).astype(np.float)
    return seq.sum() / seq.size
def mse(seq:list):
    seq = np.array(seq).astype(np.float)
    return np.sqrt(((seq - mean(seq))**2/seq.size).sum())
digit = input()
seq = []
while digit != "end":
    seq.append(digit)
    digit = input()

print("\n\n\nsequence for scoring = ", str(seq))    
print("maximum = ", maxim(seq))
print("minimum = ", minim(seq))
print("mean value = ", mean(seq))
print("mean squared error = ", mse(seq))
MAX_SIZE = int(input("enter the maximum size of array:"))
numbers = [i for i in range(MAX_SIZE // 2, MAX_SIZE + 1) if i%5 == 0] + [i for i in range(MAX_SIZE // 2 - 1) if i%5==0]
print(numbers)<jupyter_output>enter the maximum size of array:1999
[1000, 1005, 1010, 1015, 1020, 1025, 1030, 1035, 1040, 1045, 1050, 1055, 1060, 1065, 1070, 1075, 1080, 1085, 1090, 1095, 1100, 1105, 1110, 1115, 1120, 1125, 1130, 1135, 1140, 1145, 1150, 1155, 1160, 1165, 1170, 1175, 1180, 1185, 1190, 1195, 1200, 1205, 1210, 1215, 1220, 1225, 1230, 1235, 1240, 1245, 1250, 1255, 1260, 1265, 1270, 1275, 1280, 1285, 1290, 1295, 1300, 1305, 1310, 1315, 1320, 1325, 1330, 1335, 1340, 1345, 1350, 1355, 1360, 1365, 1370, 1375, 1380, 1385, 1390, 1395, 1400, 1405, 1410, 1415, 1420, 1425, 1430, 1435, 1440, 1445, 1450, 1455, 1460, 1465, 1470, 1475, 1480, 1485, 1490, 1495, 1500, 1505, 1510, 1515, 1520, 1525, 1530, 1535, 1540, 1545, 1550, 1555, 1560, 1565, 1570, 1575, 1580, 1585, 1590, 1595, 1600, 1605, 1610, 1615, 1620, 1625, 1630, 1635, 1640, 1645, 1650, 1655, 1660, 1665, 1670, 1675, 1680, 1685, 1690, 1695, 1700, 1705, 1710, 1715, 1720, 1725, 1730, 1735, 1740, 1745, 1750, 1755, 1760, 1765, 1770, 1775, 1780, 1785, 1790, 1795, 18[...]<jupyter_text>problem 2<jupyter_code>def bubble_sort(lst):
    flag = True
    while flag:
        flag = False
        for i in range(len(lst) - 1):
            if lst[i] >lst[i+1]:
                lst[i], lst[i+1] = lst[i+1], lst[i]
                
                flag = True
    return lst      
import random

def quick_sort(lst):
    
    if len(lst) <= 1:
        return lst
    
    else:
        
        left_part = []
        right_part = []
        pivot_part = []
        pivot = random.choice(lst)
        
        for i in range(len(lst)):
            
            if lst[i] < pivot:
                left_part.append(lst[i])
            
            elif lst[i] > pivot:
                right_part.append(lst[i])
                
            else:
                pivot_part.append(lst[i])
    return quick_sort(left_part) + pivot_part + quick_sort(right_part)
quick_sort([100, 2, 3, 5, 4])
bubble_sort([1, 100, 55, 1919191, 37, -1, -23923, -50, 0, 0])<jupyter_output><empty_output><jupyter_text>problem 3<jupyter_code>n = int(input("enter the size of dictionary"))
dct  = dict([input('enter the data in format: key value --> ').split() for _ in range(n)])


print({value:key for key, value in dct.items()})
print({value:key for key, value in zip(dct.keys(), dct.values())})<jupyter_output>enter the size of dictionary5
enter the data in format: key value --> a 2
enter the data in format: key value --> v 4
enter the data in format: key value --> b 5
enter the data in format: key value --> g 6
enter the data in format: key value --> h 7
{'2': 'a', '4': 'v', '5': 'b', '6': 'g', '7': 'h'}
{'2': 'a', '4': 'v', '5': 'b', '6': 'g', '7': 'h'}<jupyter_text>problem 4<jupyter_code>from math import sqrt
[num for num in range(2500) if num % 10 == 1 and sqrt(num).is_integer()]<jupyter_output><empty_output><jupyter_text>EXTRA 1 функция *transformer* - попытка решить задачу в стиле С, ну и она решена, но только для типа int.Функция *transform* реализована в общем виде.<jupyter_code>def transformer(lst:list):
    arr = list()
    i = 0
    j = -1
    if list(enumerate(lst))[-1][0] % 2  == 0:
        while id(lst[i]) != id(lst[j]):
            arr.append(lst[i] + lst[j])
            i += 1
            j -= 1
    else:
        while id(a[i]) - id(a[j]) != 32:
            arr.append(lst[i] + lst[j])
            i += 1
            j -= 1

    return arr
def transform(lst):
    ans = []
    length = list(enumerate(lst))[-1][0] + 1
    for i, j in zip(np.arange(length // 2), np.arange(-1, - length //2 -1, -1)):
        ans.append(lst[i] + lst[j])
    return ans
transform([i for i in range(10)])<jupyter_output><empty_output><jupyter_text>EXTRA 2<jupyter_code>set_1 = set(input())
set_2 = set(input())


set_1.remove(" ")
set_2.remove(" ")

def set_operations(set_1, set_2):
    
    print("intersection: ",  set_1.intersection(set_2))
    print("symmetric difference: ", set_1.symmetric_difference(set_2))
    print("union: ", set_1.union(set_2))
    
set_operations(set_1, set_2)<jupyter_output>1 2 3 4 5 6
4 5 6 7 8 9 
intersection:  {'4', '5', '6'}
symmetric difference:  {'7', '3', '9', '1', '8', '2'}
union:  {'2', '3', '7', '9', '1', '5', '6', '8', '4'}<jupyter_text>EXTRA 3<jupyter_code>def example_func(a, b=None, c=None, *args, **kwargs):
    print(a)
    print(b)
    print(c)
    print(args)
    print(kwargs)
example_func(1)
example_func(1, 2, 3, 4, k = "k")
example_func(1, d=10, g=8, b=9)<jupyter_output>1
9
None
()
{'d': 10, 'g': 8}
{'fraction_non_alphanumeric': 0.1718132854578097, 'fraction_numerical': 0.14685816876122082, 'mean_word_length': 2.9906876790830945, 'pattern_counts': {'":': 1, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '538762', 'license': 'MIT', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2234, 'n_words': 620, 'path': 'week_01/seminar_07_09.ipynb', 'repo_name': 'vlasenckov/MIPT_py_3_term', 'size': '5580'}