快速問題?我想知道是否有pythonic方式來獲得以下。找到defaultdict中元素的數量(列表)python
我有一個defaultdict(名單)
foo = {"a":[1,2,3], "b":[3]....} and so on.
有沒有寫返回我,只有其表有長度超過鍵一功能的Python的方式「N」
因此,例如
def return_keys_based_on_value_length(num,dictionary):
key_list = []
for k,v in dictionary:
if len(v)>= num:
key_list.append(k)
return key_list
有沒有一種pythonic的方式來做到這一點? 感謝
我不認爲過濾器是最好的Ť o如果您還需要它也可用於地圖。 – 2012-04-15 21:21:49