检测和搜索列表元素
| Position[list,form] | form 在 list 中的位置 |
| Count[list,form] | form 作为 list 的元素所给出的次数 |
| MemberQ[list,form] | 检测 form 是否为 list 的元素 |
| FreeQ[list,form] | 检测 form 是否不在 list 中 |
"获得列表的部分元素" 讨论如何根据元素的位置或标号提取列表的元素. Mathematica 也有根据元素的值搜索和检测列表元素的函数.
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
| In[3]:= |
| Out[3]= |
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
如同 "寻找与模式匹配的表达式" 节讨论的那样,函数 Count 和 Position,以及 MemberQ 和 FreeQ,不仅能用于搜索"特定"的列表元素,而且能搜索与特定"模式"相匹配的元素类.
