Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions T6_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with open('nginx_logs.txt', 'r', encoding='utf-8') as f:
line = f.readline()
result = []
while line:
new_tuple = (line.split(' - - ')[0], line.split(' - - ')[1].split('"')[1].split(' ')[0], line.split(' - - ')[1].split(' ')[3])
result.append(new_tuple)
line = f.readline()
print(result)
print(result[0])
print(result[-1])
16 changes: 16 additions & 0 deletions T6_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from itertools import zip_longest
from json import dump

with open('users.csv', 'r', encoding='utf-8') as f_users:
name = f_users.read()
names = name.split('\n')

with open('hobby.csv', 'r', encoding='utf-8') as f_hobby:
hobby = f_hobby.read()
hobbies = hobby.split('\n')

new = {k.replace(',', ' '): n if len(names) >= len(hobbies) else exit(1) for k, n in zip_longest(names, hobbies, fillvalue=None)}

with open('my_dict.json', 'w', encoding='utf-8') as f_dict:
dump(new, f_dict, ensure_ascii=False, indent=5)
print(new)
10 changes: 10 additions & 0 deletions T6_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from itertools import zip_longest
from json import dump

with open('users.csv', 'r', encoding='utf-8') as f_users:
with open('hobby.csv', 'r', encoding='utf-8') as f_hobby:
us_hobby = zip_longest(f_users, f_hobby, fillvalue=None)

with open('my_dict.txt', 'w', encoding='utf-8') as f_dict:
for el in us_hobby:
print(f"{str(el[0]).strip().replace(',', ' ')}: {str(el[1]).strip()}", file=f_dict)
7 changes: 7 additions & 0 deletions T6_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import add_sales
import show_sales

add_sales(input())

x = input().split(' ')
show_sales(*x)
6 changes: 6 additions & 0 deletions add_sales.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def add_sales(p):
with open('bakery.csv', 'a', encoding='utf-8') as f:
f.write(p + '\n')


add_sales(input())
6 changes: 6 additions & 0 deletions hobby.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Ароматерапия
Астрономия
Аэробика
Аэрография
Бадминтон
Батут
51,462 changes: 51,462 additions & 0 deletions nginx_logs.txt

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions show_sales.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import time

def show_sales(*args):

with open('bakery.csv', 'r', encoding='utf-8') as f:
if len(args) == 0:
print(f.read())

elif len(args) == 1:
str_1 = f.read()
print(*str_1.split('\n')[int(args[0]) - 1:], sep='\n')

else:
str_2 = f.read()
print(*str_2.split('\n')[int(args[0]) - 1: int(args[1])], sep='\n')


x = input().split(' ')
start_time = time.time()
show_sales(*x)
print(time.time() - start_time)

8 changes: 8 additions & 0 deletions users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Никитин,Даниил,Денисович
Соколов,Ярослав,Иванович
Михайлова,Варвара,Марковна
Куликова,Малика,Львовна
Мартынова,Василиса,Матвеевна
Александров,Борис,Владиславович
Федоров,Демид,Алексеевич
Маслова,Виктория,Яновна