Position
Usage
• Position[expr, pattern] 给出出现在expr中匹配pattern的对象的位置列表。
• Position[expr, pattern, levspec] 仅查找出现在由levspec指定的层的对象。
• Position[expr, pattern, levspec, n] 给出找到的前n个对象位置。
Notes
• Position[expr, pattern] 轮流测试expr的所有子部分试图找到匹配pattern的一个对象。 • Position 以在Extract, ReplacePart和MapAt中适于使用的形式返回一个位置列表。这个形式和在Part中使用的形式不同。 • 对Position的缺省层指定是{0, Infinity},有头Heads -> True。 • 一个由Position返回的部分指定{}表示整个expr. • Position[list, pattern, 1 , Heads -> False] 仅查找作为 list的完整元素出现的对象位置。
Further Examples
The symbol c occurs in the third position of this list.
In[1]:=
|
Out[1]=
|
This gives the positions of the elements of the list that are manifestly powers.
In[2]:=
|
Out[2]=
|
The head of the expression (List in position 0) and the first two elements of the expression (a and Pi) have head Symbol.
In[3]:=
|
Out[3]=
|
In[4]:=
|
Out[4]=
|
In[5]:=
|
|