Dmitry Telenkov 4 hónapja
szülő
commit
08f3bd1cc7
2 módosított fájl, 96 hozzáadás és 34 törlés
  1. 63 34
      courses/python_func/sort.py
  2. 33 0
      tmp/tmp.txt

+ 63 - 34
courses/python_func/sort.py

@@ -81,29 +81,57 @@ def print_order_rating(lst):
     new_dict = {}
     for driver in lst:
         if driver[0] not in new_dict.keys():
-            new_dict[driver[0]] = driver[1]
+            new_dict[driver[0]] = [driver[1]]
         else:
-            new_dict[driver[0]] = (new_dict[driver[0]] + driver[1])/2
+            new_dict[driver[0]].append(driver[1])
+
+    for key, value in new_dict.items():
+        new_dict[key] = sum(value)/len(value)
 
     new_list = [[key, value] for key, value in new_dict.items()]
-    new_list = sorted(new_list, key=lambda x: -x[1])
+    new_list = sorted(new_list, key=lambda x: (-x[1], x[0].lower()))
     
     for item in new_list:
         print(f'{item[0]} {item[1]}')
 
 
-    print(new_list)
+def print_statistic(lst):
+    new_dict = {}
+    for autor in lst:
+        if autor[0] not in new_dict.keys():
+            new_dict[autor[0]] = set()
+            new_dict[autor[0]].add(autor[1])
+        else:
+            new_dict[autor[0]].add(autor[1])
+
+    for key, value in new_dict.items():
+        new_dict[key] = len(value)
+
+    new_list = sorted(new_dict.items(), key=lambda x: (-x[1], x[0].lower()))
 
-    # sorted_list = sorted(new_dict, key=new_dict.get)
+    for item in new_list:
+        print(f'Количество уникальных комментаторов у {item[0]} - {item[1]}')
 
-    # print(sorted_list)
+    # print(new_list)
 
-    # for item in sorted_list:
-    #     print(item)
+    # print(new_dict)
 
+    # new_list = []
     # for key, value in new_dict.items():
-    #     print(key, value)
+    #     new_list
+
+
+
+def set_test():
+    my_set = set()    
+
+    for i in range(5):
+        my_set.add(i)
 
+    for i in range(5):
+        my_set.add(i)
+    
+    print(my_set)
 
 
 
@@ -150,36 +178,37 @@ def main():
     print_best_and_worst_laureate(laureates)
     """
 
+    """
     drivers = [
-    ('Джек', 2),
-    ('Джек', 3),
-    ('Гермиона', 5),
-    ('Билл', 4),
-    ('Билл', 4),
-    ('Гермиона', 3),
-    ('Джек', 2),
-    ('ЯЯ', 5),
-    ('ФФФ', 5),
-    ('Билл', 4),
-    ('Укк', 4),
-    ('Билл', 3),
-    ('Джек', 2),
-    ('Джек', 2),
-    ('Гермиона', 5),
-    ('Билл', 2),
-    ('ФФФ', 4),
-    ('Билл', 3),
-    ('ФФФ', 3),
-    ('Джек', 2),
-    ('Джек', 1),
-    ('Гермиона', 5),
-    ('Билл', 2),
-    ('Курт', 5),
-    ('Билл', 3),
+    ('Зина', 5),
+    ('Зина', 3),
+    ('Гермиона', 4),
+    ('Гермиона', 4),
+    ('александр', 4),
     ]
     
     print_order_rating(drivers)
+    """
+
+    data = [
+    ('7', 'opushka'),
+    ('1', 'opushka'),
+    ('2', 'opushka'),
+    ('3', 'opushka'),
+    ('2', 'opushka'),
+    ('1', 'opushka'),
+    ('2', 'opushka'),
+    ('5', 'opushka'),
+    ('6', 'opushka'),
+    ('6', 'opushka'),
+    ]
+
     
+    print_statistic(data)
+
+
+
+
 
 if __name__ == '__main__':
     main()

+ 33 - 0
tmp/tmp.txt

@@ -0,0 +1,33 @@
+DF awer f SSAFASAFAS awr fsdfsdaf
+sdfa wer 
+sadf sdafsdf erqwr sadf sdafsdf
+sadf sdf werw sdf gklj lkwqejr
+sdfkjsa weroqw klsdjf qwerj 
+The oper deleting, changing, yanking, formatting, etc.sfds sdasdf Ajfdsdfjsd
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The motion represents the piece of text to which to apply the action defined by the operator.
+The operator determines which action you want to perform: deleting, changing, yanking, formatting, etc.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The motion represents the piece of text to which to apply the action defined by the operator.
+The operator determines which action you want to perform: deleting, changing, yanking, formatting, etc.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The motion represents the piece of text to which to apply the action defined by the operator.
+The operator determines action you want to : deleting, changing, yanking, formatting, etc.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The motion represents the piece of text to which to apply the action defined by the operator.
+The operator determines which action you want to perform: deleting, changing, yanking, formatting, etc.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.sdf
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The count allows you to multiply the effect of an operator by performing an action a count number of times.
+The Count aLlows youEffect An By Performing An action a number of times.
+the mOtIOn rePiecE of text to which to apply the action defined by the operator.
+dF sdf e qwer
+df sdf e qwer
+df sdf e qwer
+df sdf e qwer
+df sdf e qwer
+df sdf e qwer