【发布时间】:2026-01-21 18:10:01
【问题描述】:
d = {'key1':['hello', 'ab', 'a', 'morning', 'sunset', 'metaphysics'],
'key2':['hi', 'morning', 'sunset', 'metaphysics'],
'key3':['hey', 'sunset', 'metaphysics']}
我有一个字典 d,我只想保留那些长度为 5 或更大的元素。所以我希望我的输出是
d = {'key1':['hello', 'morning', 'sunset', 'metaphysics'],
'key2':['morning', 'sunset', 'metaphysics'],
'key3':['sunset', 'metaphysics']}
我在这里查看How to find length of dictionary values,但这确实有很大帮助。
谁能帮忙?
【问题讨论】:
标签: python-3.x string list loops dictionary