{"id":1069638,"date":"2025-01-08T10:50:47","date_gmt":"2025-01-08T02:50:47","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1069638.html"},"modified":"2025-01-08T10:50:49","modified_gmt":"2025-01-08T02:50:49","slug":"%e5%9c%a8python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%9c%a8%e5%88%97%e8%a1%a8%e4%b8%adfind-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1069638.html","title":{"rendered":"\u5728python\u4e2d\u5982\u4f55\u5728\u5217\u8868\u4e2dfind"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100558\/3900f772-6c36-48e9-8f9b-03da82e96461.webp\" alt=\"\u5728python\u4e2d\u5982\u4f55\u5728\u5217\u8868\u4e2dfind\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u5217\u8868\u4e2d\u67e5\u627e\u5143\u7d20\uff0c\u5305\u62ec\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57\u3001<code>index()<\/code>\u65b9\u6cd5\u3001<code>find()<\/code>\u65b9\u6cd5\uff08\u5728\u5b57\u7b26\u4e32\u4e2d\uff09\u3001<code>list comprehension<\/code>\u7b49\u3002<strong>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57\u3001\u4f7f\u7528<code>index()<\/code>\u65b9\u6cd5\u3001\u904d\u5386\u5217\u8868\u3001\u4f7f\u7528<code>filter()<\/code>\u51fd\u6570<\/strong>\u3002\u6211\u4eec\u5c06\u8be6\u7ec6\u5c55\u5f00\u5176\u4e2d\u7684\u4e00\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57\u662f\u6700\u7b80\u5355\u3001\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u5b83\u53ef\u4ee5\u7528\u4e8e\u68c0\u67e5\u67d0\u4e2a\u5143\u7d20\u662f\u5426\u5b58\u5728\u4e8e\u5217\u8868\u4e2d\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>if element in my_list:<\/p>\n<p>    print(f&quot;{element} is in the list&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>in<\/code>\u5173\u952e\u5b57\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7b80\u6d01\u6027\u548c\u76f4\u89c2\u6027\u3002\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\uff0c\u9002\u5408\u4e8e\u68c0\u67e5\u5217\u8868\u4e2d\u662f\u5426\u5b58\u5728\u67d0\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528<code>index()<\/code>\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><code>index()<\/code>\u65b9\u6cd5\u7528\u4e8e\u67e5\u627e\u5143\u7d20\u5728\u5217\u8868\u4e2d\u7684\u4f4d\u7f6e\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u7d22\u5f15\u3002\u5982\u679c\u5143\u7d20\u4e0d\u5728\u5217\u8868\u4e2d\uff0c\u4f1a\u5f15\u53d1\u4e00\u4e2a<code>ValueError<\/code>\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>try:<\/p>\n<p>    index = my_list.index(element)<\/p>\n<p>    print(f&quot;Element {element} found at index {index}&quot;)<\/p>\n<p>except ValueError:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>index()<\/code>\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u68c0\u67e5\u5143\u7d20\u662f\u5426\u5b58\u5728\uff0c\u8fd8\u53ef\u4ee5\u5f97\u5230\u5143\u7d20\u7684\u4f4d\u7f6e\u3002\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662fO(n)\uff0c\u5728\u9700\u8981\u77e5\u9053\u5143\u7d20\u4f4d\u7f6e\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u904d\u5386\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u624b\u52a8\u904d\u5386\u5217\u8868\u662f\u4e00\u79cd\u7075\u6d3b\u4f46\u76f8\u5bf9\u8f83\u7e41\u7410\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u67e5\u627e\u8fc7\u7a0b\u4e2d\u6267\u884c\u989d\u5916\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>found = False<\/p>\n<p>for i, e in enumerate(my_list):<\/p>\n<p>    if e == element:<\/p>\n<p>        found = True<\/p>\n<p>        print(f&quot;Element {element} found at index {i}&quot;)<\/p>\n<p>        break<\/p>\n<p>if not found:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a\u624b\u52a8\u904d\u5386\u5217\u8868\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u5728\u67e5\u627e\u8fc7\u7a0b\u4e2d\u6267\u884c\u81ea\u5b9a\u4e49\u64cd\u4f5c\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u770b\u4f3c\u7e41\u7410\uff0c\u4f46\u5728\u7279\u5b9a\u573a\u666f\u4e0b\u662f\u975e\u5e38\u6709\u7528\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528<code>filter()<\/code>\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>filter()<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u7b5b\u9009\u51fa\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\u3002\u7ed3\u5408<code>lambda<\/code>\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u67e5\u627e\u7279\u5b9a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>filtered_list = list(filter(lambda x: x == element, my_list))<\/p>\n<p>if filtered_list:<\/p>\n<p>    print(f&quot;Element {element} found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>filter()<\/code>\u51fd\u6570\u9002\u5408\u7528\u4e8e\u66f4\u590d\u6742\u7684\u6761\u4ef6\u7b5b\u9009\u3002\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u540c\u6837\u4e3aO(n)\uff0c\u4f46\u5728\u5904\u7406\u66f4\u590d\u6742\u6761\u4ef6\u65f6\u975e\u5e38\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u65b0\u7684\u5217\u8868\u3002\u5728\u67e5\u627e\u5143\u7d20\u65f6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u6765\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\u7684\u5b50\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>found_elements = [x for x in my_list if x == element]<\/p>\n<p>if found_elements:<\/p>\n<p>    print(f&quot;Element {element} found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7b80\u6d01\u6027\u548c\u53ef\u8bfb\u6027\u3002\u5b83\u975e\u5e38\u9002\u5408\u7528\u4e8e\u7b80\u5355\u7684\u7b5b\u9009\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528<code>any()<\/code>\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>any()<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u68c0\u67e5\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u662f\u5426\u5b58\u5728\u81f3\u5c11\u4e00\u4e2a\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>if any(x == element for x in my_list):<\/p>\n<p>    print(f&quot;Element {element} found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>any()<\/code>\u51fd\u6570\u975e\u5e38\u9ad8\u6548\uff0c\u9002\u5408\u7528\u4e8e\u5224\u65ad\u6761\u4ef6\u662f\u5426\u88ab\u6ee1\u8db3\u3002\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662fO(n)\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528<code>collections.Counter<\/code><\/h3>\n<\/p>\n<p><p><code>collections.Counter<\/code>\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u8ba1\u6570\u7684\u5bb9\u5668\uff0c\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u7edf\u8ba1\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>counter = Counter(my_list)<\/p>\n<p>if counter[element] &gt; 0:<\/p>\n<p>    print(f&quot;Element {element} found {counter[element]} time(s)&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>Counter<\/code>\u4e0d\u4ec5\u53ef\u4ee5\u68c0\u67e5\u5143\u7d20\u662f\u5426\u5b58\u5728\uff0c\u8fd8\u53ef\u4ee5\u7edf\u8ba1\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002\u9002\u5408\u7528\u4e8e\u9700\u8981\u9891\u7e41\u67e5\u627e\u548c\u7edf\u8ba1\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528<code>numpy<\/code>\u5e93<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5305\u542b\u5927\u91cf\u6570\u636e\u7684\u5217\u8868\uff0c\u4f7f\u7528<code>numpy<\/code>\u5e93\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u67e5\u627e\u6548\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>np_array = np.array(my_list)<\/p>\n<p>if element in np_array:<\/p>\n<p>    print(f&quot;Element {element} found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>numpy<\/code>\u5e93\u5728\u5904\u7406\u5927\u6570\u636e\u65f6\u975e\u5e38\u9ad8\u6548\u3002\u5b83\u4f7f\u7528C\u8bed\u8a00\u7f16\u5199\uff0c\u6027\u80fd\u4f18\u5f02\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u4f7f\u7528<code>pandas<\/code>\u5e93<\/h3>\n<\/p>\n<p><p><code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u9002\u5408\u5904\u7406\u7ed3\u6784\u5316\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>series = pd.Series(my_list)<\/p>\n<p>if element in series.values:<\/p>\n<p>    print(f&quot;Element {element} found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a<code>pandas<\/code>\u5e93\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u3002\u5b83\u7684\u67e5\u627e\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u5408\u5904\u7406\u590d\u6742\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u67e5\u627e\u5143\u7d20\u3002\u8fd9\u79cd\u65b9\u6cd5\u7075\u6d3b\u5ea6\u6700\u9ad8\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u8fdb\u884c\u5b9a\u5236\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_element(lst, el):<\/p>\n<p>    for i, e in enumerate(lst):<\/p>\n<p>        if e == el:<\/p>\n<p>            return i<\/p>\n<p>    return -1<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>element = 3<\/p>\n<p>index = find_element(my_list, element)<\/p>\n<p>if index != -1:<\/p>\n<p>    print(f&quot;Element {element} found at index {index}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;Element {element} is not in the list&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff1a\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u4f18\u70b9\u5728\u4e8e\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u3002\u9002\u5408\u7528\u4e8e\u7279\u5b9a\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u67e5\u627e\u5217\u8868\u5143\u7d20\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002<strong><code>in<\/code>\u5173\u952e\u5b57\u9002\u5408\u5feb\u901f\u68c0\u67e5\uff0c<code>index()<\/code>\u9002\u5408\u9700\u8981\u77e5\u9053\u4f4d\u7f6e\u65f6\uff0c\u904d\u5386\u5217\u8868\u9002\u5408\u6267\u884c\u989d\u5916\u64cd\u4f5c\uff0c<code>filter()<\/code>\u548c<code>any()<\/code>\u9002\u5408\u590d\u6742\u6761\u4ef6\u7b5b\u9009\uff0c<code>Counter<\/code>\u9002\u5408\u7edf\u8ba1\u5143\u7d20\u6b21\u6570\uff0c<code>numpy<\/code>\u548c<code>pandas<\/code>\u9002\u5408\u5927\u6570\u636e\u5904\u7406\uff0c\u81ea\u5b9a\u4e49\u51fd\u6570\u9002\u5408\u7279\u5b9a\u9700\u6c42<\/strong>\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u6548\u7387\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u67e5\u627e\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57\u6765\u68c0\u67e5\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5728\u5217\u8868\u4e2d\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5217\u8868<code>my_list<\/code>\uff0c\u8981\u67e5\u627e\u5143\u7d20<code>x<\/code>\u662f\u5426\u5b58\u5728\u4e8e\u8be5\u5217\u8868\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>if x in my_list:<\/code>\u3002\u5982\u679c\u5b58\u5728\uff0c\u7a0b\u5e8f\u4f1a\u8fd4\u56de<code>True<\/code>\uff0c\u5426\u5219\u8fd4\u56de<code>False<\/code>\u3002<\/p>\n<p><strong>Python\u63d0\u4f9b\u4e86\u54ea\u4e9b\u65b9\u6cd5\u6765\u83b7\u53d6\u5217\u8868\u4e2d\u5143\u7d20\u7684\u7d22\u5f15\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>list.index(value)<\/code>\u65b9\u6cd5\u6765\u627e\u5230\u5143\u7d20\u5728\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u51fa\u73b0\u4f4d\u7f6e\u3002\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\uff0cPython\u4f1a\u629b\u51fa\u4e00\u4e2a<code>ValueError<\/code>\u5f02\u5e38\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u5148\u4f7f\u7528<code>in<\/code>\u5173\u952e\u5b57\u786e\u8ba4\u5143\u7d20\u662f\u5426\u5728\u5217\u8868\u4e2d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u5217\u8868\u4e2d\u67e5\u627e\u591a\u4e2a\u5143\u7d20\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u89e3\u6790\u6216\u5faa\u73af\u904d\u5386\u6765\u67e5\u627e\u591a\u4e2a\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u5217\u8868\u7406\u89e3\u6765\u8fc7\u6ee4\u51fa\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<code>found_items = [item for item in my_list if item in search_list]<\/code>\uff0c\u5176\u4e2d<code>search_list<\/code>\u662f\u4f60\u8981\u67e5\u627e\u7684\u5143\u7d20\u96c6\u5408\u3002\u8fd9\u6837\u7684\u65b9\u5f0f\u65e2\u9ad8\u6548\u53c8\u7b80\u6d01\uff0c\u4fbf\u4e8e\u7ba1\u7406\u548c\u7ef4\u62a4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u5217\u8868\u4e2d\u67e5\u627e\u5143\u7d20\uff0c\u5305\u62ec\u4f7f\u7528in\u5173\u952e\u5b57\u3001index()\u65b9\u6cd5\u3001find()\u65b9\u6cd5\uff08\u5728\u5b57 [&hellip;]","protected":false},"author":3,"featured_media":1069644,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1069638"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1069638"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1069638\/revisions"}],"predecessor-version":[{"id":1069648,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1069638\/revisions\/1069648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1069644"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1069638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1069638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1069638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}