-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lovro Šubelj
committed
Feb 7, 2025
1 parent
e86b157
commit eae9f4c
Showing
6 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |