This commit is contained in:
2509165027
2026-06-23 11:22:41 +08:00
parent 1e00974a79
commit 74906f0596
4 changed files with 337 additions and 0 deletions

37
q2_1_crawler/q2_2.py Normal file
View File

@@ -0,0 +1,37 @@
import json
with open('q2_1_crawler\movies.json', 'r', encoding='utf-8') as f:
movies = json.load(f)
if movies:
sorted_by_rating = sorted(movies, key=lambda x: x['rating'])
lowest_movie = sorted_by_rating[0]
highest_movie = sorted_by_rating[-1]
print("2.1 最高评分电影:")
print(f"电影名: {highest_movie['title']}, 评分: {highest_movie['rating']}")
print("\n最低评分电影:")
print(f"电影名: {lowest_movie['title']}, 评分: {lowest_movie['rating']}")
genre_counts = {}
for movie in movies:
genre = movie['genre']
genre_counts[genre] = genre_counts.get(genre, 0) + 1
print("\n2.2 各类型电影数量字典:")
print(genre_counts)
director_counts = {}
for movie in movies:
director = movie['director']
director_counts[director] = director_counts.get(director, 0) + 1
print("\n2.3 各导演电影数量字典:")
print(director_counts)
count_2020_later = 0
for movie in movies:
if movie['year'] >= 2020:
count_2020_later += 1
print(f"\n2.4 2020年以后上映的电影数量: {count_2020_later}")