Message Boards Message Boards


Struggling with list from datafile

Posted 10 years ago
2 Replies
1 Total Likes
I got a list from a datafile:
ctxt = Flatten[ StringSplit[Import["d.txt", "Data"], ","]];

Then I got every third number:
lst3 = ctxt[[3 ;; ;; 3]];

When "looked" at lst3 in an outcell it looked like a list of numbers {79, 2, 8, 54 ...}

But it is actually a list of strings: {"79", "2", "8", "54" ...}

It took me a long time to make this realization and to fix my code:
lst3 = ToExpression /@ ctxt[[3 ;; ;; 3]];

What is going on?  Why does the outcell "look" incorrect?

Thanks in advance
POSTED BY: Joe Gilray
2 Replies
Posted 10 years ago
Thanks Ilian.  Makes sense.
POSTED BY: Joe Gilray
Strings are always displayed without quotes in output cells (this could be customized by setting ShowStringCharacters -> True in the stylesheet).
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract