如何拆分字典键并更改 python 中的类型

How to split dictionary keys and change the type in python

我的任务是找出字典中的 'keys' 是 300 级或以上。像这样的字典的一个例子是 {'CSCI 160': 4, 'CSCI 330': 3, 'MATH 208': 3, 'EE 201":4}。我将如何拆分键并将数字部分转换为整数?

此代码将使用原始字典中的键值对创建一个新字典,但前提是值大于或等于 300。

filtered_dict = {key: val for key, val in my_dict.items() if int(key.rsplit(' ', 1)[1]) >= 300}