1
$\begingroup$

I have a list of words

list={"ingenuous", "forgotten", "tree", "supercomput", "hundred"}

How can I put the letters of each word in an element of a table such as here:

enter image description here

$\endgroup$
4
  • $\begingroup$ You misspelled "ingenious". In any event: have you seen Characters[]? $\endgroup$ Jul 8, 2016 at 12:16
  • 1
    $\begingroup$ Better answers are given, but here is quick one: TableForm[Characters /@ list, TableHeadings -> {list, None}] . $\endgroup$ Jul 8, 2016 at 12:31
  • $\begingroup$ @AntonAntonov Note that TableForm cannot set gridding line. :) $\endgroup$
    – yode
    Jul 8, 2016 at 12:42
  • $\begingroup$ @yode I know, that is why I said there are better solutions... Also, I think TableForm is under-appreciated, that is why I provided a line with it. $\endgroup$ Jul 8, 2016 at 12:49

2 Answers 2

6
$\begingroup$
list = {"ingenious", "forgotten", "tree", "supercomput", "hundred"};
list /. word_String :> Join[{word}, Characters@word] // Grid[#, Dividers -> All] &

table

$\endgroup$
4
  • $\begingroup$ This is a winning answer I think. :) $\endgroup$
    – yode
    Jul 8, 2016 at 12:34
  • 1
    $\begingroup$ If one is not deterred by /., :>,@, //, #& and friends this style of writing mathematica code is imho the most readable of all. $\endgroup$
    – Sascha
    Jul 8, 2016 at 12:36
  • 1
    $\begingroup$ I'd have done Prepend[Characters[word], word] myself. $\endgroup$ Jul 8, 2016 at 13:11
  • $\begingroup$ Another possibility is using {word} ~Join~ Characters@word. Sometimes (not necessarily in this case) infix notation helps to further convey what the particular line of code does (precedence becomes somewhat difficult to assess though) $\endgroup$
    – Sascha
    Jul 8, 2016 at 15:20
2
$\begingroup$

As the promp of Sascha's answer,I simplify this code be

list={"ingenuous","forgotten","tree","supercomput","hundred"};
Grid[Join[List/@list,Characters/@list,2],Frame->All,Spacings->{2.6,0.5}]

$\endgroup$
0

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.