37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
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} 部") |