In the nested list, how to check if a given indexing sequence is valid in mathematics

I have a very irregular nested list myListin mma, whenever 1,1,2,3,1I get an integer sequence, such as any length, I want to know if

myList[[1,1,2,3,1]]

; because if it is not, I get an error

Part::partw: part... does not exist

Thank.

+5
source share
3 answers
   Quiet[
       Check[mylist[[1, 1, 2, 3, 1]], Print[False], Part::partd], 
   Part::partd];  

You can replace Print [False] for any other action ...

Edit

To check both partd and partw messages , the syntax is:

Quiet[Check[{{{1, 3}}, {2}}[[1, 4, 2, 3, 1]], 
    Print[False], {Part::partd, Part::partw}], 
   {Part::partd, Part::partw}];

NTN!

+3
source
+3

.

Quiet[MemberQ[#, #[[1, 4, 2, 3, 1]], Infinity] &[{{{1, 3}}, {2}}]]

False.

true false , ( ) .

Quiet[MemberQ[#, #[[1, 1, 2]], Infinity] &[{{{1, 3}}, {2}}]]

True.

belisarius , .

0

All Articles