filter items in a python dictionary where keys contain a specific string

后端 未结 5 1840
忘掉有多难
忘掉有多难 2020-12-02 11:44

I\'m a C coder developing something in python. I know how to do the following in C (and hence in C-like logic applied to python), but I\'m wondering what the \'Python\' way

5条回答
  •  误落风尘
    2020-12-02 12:35

    input = {"A":"a", "B":"b", "C":"c"}
    output = {k:v for (k,v) in input.items() if key_satifies_condition(k)}
    

提交回复
热议问题