Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practice 14 #59

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
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
44 changes: 44 additions & 0 deletions 1-14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import csv

with open('linkin_park.csv', 'w', newline='') as csvfile:
fieldnames = ['song', 'year']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()


writer.writerow({'year': 2003,
'song': 'Numb'})
writer.writerow({'year': 2024,
'song': 'Heavy Is the Crown'})
writer.writerow({'year': 2001,
'song': "In the End"})
writer.writerow({'year': 2024,
'song': 'Emptiness Machine'})
writer.writerow({'year': 2007,
'song': "What I've done"})
writer.writerow({'year': 2003,
'song': 'Faint'})
writer.writerow({'year': 2012,
'song': 'Burn it Down'})
writer.writerow({'year': 2003,
'song': 'Breaking the Habit'})
writer.writerow({'year': 2000,
'song': 'Papercut'})
writer.writerow({'year': 2000,
'song': 'One Step Closer'})



with open('linkin_park.csv', newline='') as csvfile:

reader = csv.DictReader(csvfile)

n = 0

for heading in reader.fieldnames:
print(heading, end=' ')
print('\n------------------------------')

for row in reader:
n += 1
print(f"{n}. {row['song']} ({row['year']})")
30 changes: 30 additions & 0 deletions 2-14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json

name = "image_info_test-dev2017.json"

with open(name) as file:

dict = json.load(file)

print(f' Кількість "images" у файлі "{name}": {len(dict["images"])}')

print(f' Кількість "categories" у файлі "{name}": {len(dict["categories"])}')

print("-"*50)

for elem in dict["images"]:
search = "000000000001.jpg"

if elem["file_name"] == search:
print (f' Для картинки "{search}":\n{" "*5}url: {elem["coco_url"]}\n{" "*5}height: {elem["height"]} \n{" "*5}width: {elem["width"]} \n{" "*5}id: {elem["id"]}')

elem_list = []

for elem in dict["images"]:

elem_list.append(elem["file_name"])

elem_list.sort(reverse=True)

print(f"{"-"*50}\n Найбільша картинка за назвою: {elem_list[0]}")