1
$\begingroup$

If I have the list {3,5,4,2}, is there a way to divide this list into smaller lists of the form {3},{5},{4},{2}?

$\endgroup$
  • 4
    $\begingroup$ Transpose[{lst}] == Thread[List[lst]] == List /@ lst == {{3}, {5}, {4}, {2}} $\endgroup$ – user1066 Jun 26 '16 at 17:09
  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Jun 26 '16 at 17:10
  • 6
    $\begingroup$ @TomD Or indeed Partition[lst, 1] $\endgroup$ – Feyre Jun 26 '16 at 17:29
  • $\begingroup$ @ Feyre. Partition[lst, 1] is good to know. Just for fun: Tuples[lst, {1}] == Flatten[{lst}, {{2}}] == MapThread[List, {lst}] ==Subsets[lst, {1}] == {{3}, {5}, {4}, {2}} $\endgroup$ – user1066 Jun 26 '16 at 20:09
  • $\begingroup$ @TomD Actually, you did know about Partition[lst,1]. See here $\endgroup$ – user1066 Jul 10 '16 at 8:37
2
$\begingroup$

Example

Code

List /@ {3,5,4,2}

Output

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

Reference

Map

$\endgroup$
  • $\begingroup$ 'List/@{3,5,4,2}' is shorter.(+1) $\endgroup$ – kglr Jun 26 '16 at 19:39
  • $\begingroup$ @kglr ;D you are right! $\endgroup$ – e.doroskevic Jun 26 '16 at 19:50
1
$\begingroup$

Since your Data are already a List you can use Part to access Values:

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

3

myList = {3, 5, 4, 2};

myList[[1]]*myList[[3]]

12

Nota Bene, everything in the comments seem right, however, you can also work with Subsets:

lst = {3, 5, 4, 2};

s1 = Subsets[lst, {1}]

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

m = s1[[1]]

{3}

n = s1[[3]]

{4}

m*n

{12}

$\endgroup$

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