# 分治法思想-判断某个元素是否在列表中

```python
# 子问题，规模为1，len(init_list)=1
def is_in_list(init_list,evl):
    return [False,True][init_list[0]==evl]

def solve(init_list,evl):
    n=len(init_list)#计算问题规模
    print(init_list)
    if n==1:
        return is_in_list(init_list,evl)
    else:
        left_list,right_list=init_list[:n//2],init_list[n//2:]
#         先判断左边，当左边为False时，才判断右边
        res=solve(left_list,evl) or solve(right_list,evl)
        return res

data=[12,3,5,77,4,9,23,56,35,8]
print(solve(data,8))
```

```
[12, 3, 5, 77, 4, 9, 23, 56, 35, 8]
[12, 3, 5, 77, 4]
[12, 3]
[12]
[3]
[5, 77, 4]
[5]
[77, 4]
[77]
[4]
[9, 23, 56, 35, 8]
[9, 23]
[9]
[23]
[56, 35, 8]
[56]
[35, 8]
[35]
[8]
True
```


---

# 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/shua-ti/si-xiang-lei/fen-zhi-fa/pan-duan-yuan-su-shi-fou-cun-zai.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.
