0
$\begingroup$

I have a doubt to confirm. Let there is a list

  f = {{l}, {c}, {d}, {e}, {1, 2, 3}, {3, 4, 5}}

And I expect it to be traversed as a normal list which I can do by,

Table[f[[i, k]], {i, Length[f]}, {k, Length[f[[i]]]}]

But if the list is

a = {b, c, d, e, {1, 2, 3}, {3, 4, 5}}

Than I get the following output

   {{}, {}, {}, {}, {1, 2, 3}, {3, 4, 5}}

Is it must that there shall be list of sublists and no single element can be kept without sublist or I am accessing it wrong way. Doesn't Mathematica automatically consider it to be sublist for obvious reason.

$\endgroup$
1
  • $\begingroup$ ...and you've just seen that Part[] does not do anything too useful to symbols, as opposed to what it does for lists and list-like objects. $\endgroup$ Jun 3, 2013 at 18:00

1 Answer 1

3
$\begingroup$

In simple form:

f = {a, b};
f[[1]]

gives you

a

as you expect. But what is the length of f[[1]]?

Length[f[[1]]]
0

Which explains why your Table operates the way it does: the length of any symbol is 0. In fact, the length of any indivisible object (like a number or a symbol or a string) is 0, as is the length of any expression for which AtomQ is True.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.