I am reading a file with Get[]
that contains a semi-colon separated sequence of sub-scripted definitions like this:
data[1] = {stuff};
data[5] = {otherStuff};
data[99] = {yetMoreStuff};
What is the cleanest way to programatically decide for what values of i
is data[i]
defined? A list of the indices would be nice, e.g. {1, 5, 99}
.
A hacky way would be to loop through the range of possible values to see which ones don't have head "data" (e.g. Select[data/@Range[1,1000],(Not[MatchQ[#,_data]])?]
), but this is unattractive since it isn't general (e.g. it won't find data[dog] = "Max";
if we remove the integer subscript requirement) and assumes that one can choose an upper bound. It would also be slow and waste memory.