Skip to content

Commit

Permalink
Add PRO2 lectures
Browse files Browse the repository at this point in the history
  • Loading branch information
Lovro Šubelj committed Feb 7, 2025
1 parent e86b157 commit eae9f4c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pro2/code/python/brackets/brackets.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
([{a}]): True
([a]{b}): True
{a}[ ](b): True
([a): False
([a)]: False
({}[])(): True
({a][b)c}: False
15 changes: 15 additions & 0 deletions pro2/code/python/brackets/brackets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

BRACKETS = {')': '(', ']': '[', '}': '{'}

def is_valid(str):
stack = []
for char in str:
if char in BRACKETS.values():
stack.append(char)
elif char in BRACKETS:
if not stack or stack.pop() != BRACKETS[char]:
return False
return not stack

for brackets in ["([{a}])", "([a]{b})", "{a}[ ](b)", "([a)", "([a)]", "({}[])()", "({a][b)c}"]:
print(brackets + ": " + str(is_valid(brackets)))
3 changes: 3 additions & 0 deletions pro2/code/python/movies/movies.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Action: Chris Evans & Robert Downey Jr. (5 movies)
Drama: Benedict Cumberbatch & Martin Freeman (9 movies)
Horror: Helena Bonham Carter & Johnny Depp (2 movies)
21 changes: 21 additions & 0 deletions pro2/code/python/movies/movies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests

def actors(movies):
cnts = {}
for movie in movies:
acts = movie['actors'].split(', ')
for act1 in acts:
for act2 in acts:
if act1 < act2:
pair = act1, act2
if pair in cnts:
cnts[pair] += 1
else:
cnts[pair] = 1
return sorted(cnts.items(), key = lambda item: item[1])[-1]

movies = requests.get("https://lovro.fri.uni-lj.si/api/movies").json()

for genre in ["Action", "Drama", "Horror"]:
(act1, act2), cnt = actors(movie for movie in movies if genre in movie['genres'])
print(f"{genre}: {act1} & {act2} ({cnt} movies)")
Binary file added pro2/code/python/paris24/paris24.pdf
Binary file not shown.
21 changes: 21 additions & 0 deletions pro2/code/python/paris24/paris24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests
import matplotlib.pyplot as plt

data = requests.get("https://lovro.fri.uni-lj.si/api/paris24").json()

results = []
for country in data:
medals = data[country]['gold'] + data[country]['silver'] + data[country]['bronze']
results.append((country, medals, medals / data[country]['population'] * 10**6))

fig, axs = plt.subplots(1, 2, figsize = [15.6, 4.8])

results.sort(key = lambda item: item[1])
axs[0].barh([c for c, _, _ in results[-20:]], [r for _, r, _ in results[-20:]], color = '0.9', ec = 'k')
axs[0].title.set_text("Število medalj")

results.sort(key = lambda item: item[2])
axs[1].barh([c for c, _, _ in results[-20:]], [r for _, _, r in results[-20:]], color = '0.9', ec = 'k', log = True)
axs[1].title.set_text("Število medalj / milijon prebivalcev")

fig.savefig("paris24.pdf", bbox_inches = 'tight')

0 comments on commit eae9f4c

Please # to comment.