TelenkovDmitry há 1 ano atrás
pai
commit
0c91eae57d

+ 28 - 0
courses/python_indi/all_any.py

@@ -0,0 +1,28 @@
+
+def test_1():
+    a = ['sfd', 'werwer', '']
+    print(all(a))
+    print(any(a))
+
+# test_1()
+
+def test_2():
+    words = ['notice', 'deter', 'west', 'brush', 'stadium',
+            'package', 'price', 'clothes', 'sword', 'apology']
+
+    check = [len(word) >= 4 for word in words]
+
+    print(check)
+    print(all(check))
+    print(all([len(word) > 4 for word in words]))
+
+    print(any([len(word) > 7 for word in words]))
+    print(any([len(word) >= 7 for word in words]))
+
+# test_2()
+
+def test_3():
+    words = list(input().split(' '))
+    print(all(['A' in word for word in words]))
+
+test_3()

+ 18 - 0
courses/python_indi/instance.py

@@ -0,0 +1,18 @@
+
+def count_strings(*args):
+    string_cnt = 0
+    for x in args:
+        if isinstance(x, str):
+            string_cnt += 1
+    return string_cnt
+
+# print(count_strings(1, 2, 43, 5))
+
+def find_keys(**kwargs):
+    name_list = []
+    for key, value in kwargs.items():
+        if isinstance(value, (list, tuple)):
+            name_list.append(key)
+    return sorted(name_list, key=str.lower)
+
+print(find_keys(t=[4, 5], W=[5, 3], A=(3, 2), a={2, 3}, b=[4]))

+ 151 - 0
courses/python_indi/zip.py

@@ -0,0 +1,151 @@
+
+from itertools import zip_longest
+
+def test_zip():
+    a = [1, 4, 3, 5]
+    b = [123, 323, 543, 234]
+    c = 'asdf'
+
+    # for i in range(4):
+    #     print(a[i], b[i])
+
+    res = zip(a, b, c)
+
+    col1, col2, col3 = zip(*res)
+
+    print(col1, col2, col3)
+
+    for i in res:
+        print(i)
+
+def test_1():
+    x = [1, 2, 3]
+    y = [4, 5, 6]
+    zipped = zip(x, y, strict=True)
+    result = list(zipped)
+    print(result)
+
+# test_1()
+
+
+def zip_longest_test():
+    ids = [1, 2, 3, 4]
+    leaders = ['Elon Mask', 'Tim Cook', 'Bill Gates', 'Yang Zhou']
+    countries = ('Australia', 'USA')
+    records = zip_longest(ids, leaders, countries)
+
+    print(list(records))
+
+    records_2 = zip_longest(ids, leaders, countries, fillvalue='Unknown')
+    print(list(records_2))
+
+
+def unzip_test():
+    record = [(1, 'Elon Mask', 'Australia'),
+          (2, 'Tim Cook', 'USA'),
+          (3, 'Bill Gates', 'USA'),
+          (4, 'Yang Zhou', 'China')]
+    ids, leaders, countries = zip(*record)
+    print(ids)
+    print(leaders)
+    print(countries)
+    
+# unzip_test()
+
+def zip_iter_1():
+    employee_numbers = [2, 9, 18, 28]
+    employee_names = ["Valentin", "Leonti", "Andrew", "Sasha"]
+    salaries = (100, 200, 3000, 450)
+
+    for name, number, salary in zip(employee_names, employee_numbers, salaries):
+        print(name, number, salary)
+
+# zip_iter_1()
+
+def zip_dict():
+    dict_one = {'name': 'John', 'last_name': 'Doe', 'job': 'Python Consultant'}
+    dict_two = {'name': 'Jane', 'last_name': 'Doe', 'job': 'Community Manager'}
+    for (k1, v1), (k2, v2) in zip(dict_one.items(), dict_two.items()):
+        print(k1, '->', v1)
+        print(k2, '->', v2)
+
+# zip_dict()
+
+def creat_dict():
+    employee_numbers = [2, 9, 18]
+    employee_names = ["Valentin", "Leonti", "Andrew"]
+
+    numbers = dict(zip(employee_numbers, employee_names))
+    employees = dict(zip(employee_names, employee_numbers))
+
+    print(numbers)
+    print('------')
+    print(employees)
+
+
+    # обновляе словаря
+    other_num = [50, 63]
+    other_names = ['Misha', 'Sergey']
+    numbers.update(zip(other_num, other_names))
+    print('------')
+    print(numbers)
+
+# creat_dict()
+
+def zip_comp():
+    employee_numbers = [2, 9, 18]
+    employee_names = ["Valentin", "Leonti", "Andrew"]
+
+    numbers = {num: name for num, name in zip(employee_numbers, employee_names)}
+    names = [name[0]*num for num, name in zip(employee_numbers, employee_names)]
+    print(numbers)
+    print(names)
+
+# zip_comp()
+
+def zip_matrix():
+    matrix = [[1, 2, 3, 4], [5, 6, 7, 8]]
+    matrix_trans = [list(i) for i in zip(*matrix)]
+    print(matrix_trans)
+
+# zip_matrix()
+
+def task_1():
+    keys = ['Ten', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety', 'One hundred']
+    values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
+    result = dict(zip(keys, values))
+    print(result)
+
+# task_1()
+
+def task_2():
+    employees = ['Pankratiy', 'Innokentiy', 'Anfisa', 'Yaroslava', 'Veniamin',
+                'Leonti', 'Daniil', 'Mishka', 'Lidochka',
+                'Terenti', 'Vladik', 'Svetka', 'Maks', 'Yura', 'Sergei']
+    identifiers = [77, 48, 88, 85, 76, 81, 62, 43, 5, 56, 17, 20, 37, 32, 96]
+
+    # employees_data = dict(zip(identifiers, employees))
+    employees_data = dict(zip(sorted(identifiers), sorted(employees)))
+    print(employees_data)
+
+# task_2()
+
+
+def combine_strings(a: str, b: str) -> str:
+    return a + b
+
+def get_sum_two_numbers(a: int, b: int) -> int:
+    return a + b
+
+def get_sum_three_numbers(a: int, b: int, c: int) -> int:
+    return a + b + c
+
+def zip_with_function(list_data, f):
+    combined_list = list(zip(*list_data))
+    combined_list = list(map(lambda args: f(*args), combined_list))
+    return combined_list
+
+
+# zip_with_function([[1, 2, 3], [4, 5, 6], [7, 8, 9]], get_sum_three_numbers)
+# zip_with_function([[1, 2, 4], [3, 5, 8]], get_sum_two_numbers)
+

+ 7 - 6
selenium/metrolog.py

@@ -15,6 +15,7 @@ class MetrologTester():
     PGW_PORT_2 = 1002
     PGW_PORT_3 = 1003
     PGW_TEST_DATA = b'abcdefghijklmnopqrstuvwxyz'
+    WEB_TIMEOUT = 0.5
 
 
     def __init__(self, ip):
@@ -38,7 +39,7 @@ class MetrologTester():
         self.driver.find_element(By.ID, 'login').send_keys(self.USER)
         self.driver.find_element(By.ID, 'pass').send_keys(self.PASWORD)
         self.driver.find_element(By.CLASS_NAME, 'btn.btn-primary').click()
-        time.sleep(2)
+        time.sleep(1)
         return True if self.driver.title == "Состояние модема" else False
 
     def test_page_click(self):
@@ -47,15 +48,15 @@ class MetrologTester():
             if self.login() == False:
                 return
             for i in range(1):
-                time.sleep(1)
+                time.sleep(self.WEB_TIMEOUT)
                 nav = self.driver.find_element(By.XPATH, "//ul[@id='nav']/li[2]/a").click()
-                time.sleep(1)
+                time.sleep(self.WEB_TIMEOUT)
                 nav = self.driver.find_element(By.XPATH, "//ul[@id='nav']/li[3]/a").click()
-                time.sleep(1)
+                time.sleep(self.WEB_TIMEOUT)
                 nav = self.driver.find_element(By.XPATH, "//ul[@id='nav']/li[1]/a").click()
-                time.sleep(1)
+                time.sleep(self.WEB_TIMEOUT)
             nav = self.driver.find_element(By.ID, 'logout').click()
-            time.sleep(1)
+            time.sleep(self.WEB_TIMEOUT)
     
     def start_web_clicker(self):
         self.web_thread.start()