# 字典推导式

代码：

```python
mcase={'a':10,'b':34,'A':7,'Z':3}

print('mcase:',mcase)
print()
print('忽略key大小写，相加key的value，且过滤掉不是a,b的')
mcase_frequency={
    k.lower():mcase.get(k.lower(),0)+mcase.get(k.lower(),0)
    for k in mcase.keys()
    if k.lower() in ['a','b']
}

print('mcase_frequency:',mcase_frequency)
print()
print('反转mcase的 k,v')
mcase_revers={v:k for k,v in mcase.items()}
print(mcase_revers)
```

结果：

```python
mcase: {'a': 10, 'b': 34, 'A': 7, 'Z': 3}

忽略key大小写，相加key的value，且过滤掉不是a,b的
mcase_frequency: {'a': 20, 'b': 68}

反转mcase的 k,v
{10: 'a', 34: 'b', 7: 'A', 3: 'Z'}
```

视频：

```
wait
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/python/2.3.8-zi-dian-tui-dao-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
