# lambda表达式

`lambda` 表达式是一行函数。\
它们在其他语言中也被称为匿名函数。如果你不想在程序中对一个函数使用两次，你也许会想用 lambda 表达式，它们和普通的函数完全一样。

**原型**

```python
    lambda 参数:操作(参数)
```

**例子**

```python
    add = lambda x, y: x + y

    print(add(3, 5))
    # Output: 8
```

这还有一些lambda表达式的应用案例，可以在一些特殊情况下使用：

**列表排序**

```python
    a = [(1, 2), (4, 1), (9, 10), (13, -3)]
    a.sort(key=lambda x: x[1])

    print(a)
    # Output: [(13, -3), (4, 1), (1, 2), (9, 10)]
```

**列表并行排序**

```python
    data = zip(list1, list2)
    data = sorted(data)
    list1, list2 = map(lambda t: list(t), zip(*data))
```


---

# 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://eastlakeside.gitbook.io/interpy-zh/lambdas.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.
