ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 07 Mar 2018 14:51:22 +0100What is a possibility to tell Sage to turn a list into a multiset?https://ask.sagemath.org/question/41418/what-is-a-possibility-to-tell-sage-to-turn-a-list-into-a-multiset/ A well-known computer algebra package features a useful command called 'Tally', which e.g. takes a list like 2,1,2,2,3,1 and returns the list of pairs (1,2),(2,3),(3,1), where the second component of each pair equals the multiplicity of the first component of the pair in the input list. Currently, I am learning more Sage, and I need some functionality like the above.
**My question.** Is there a 'native' way to do the same in Sage? Of course, I could program something like this, but what is, in your opinion, the currently 'best' way to turn an arbitrary list into a multiset, with the multiplicities conveniently recorded?Wed, 07 Mar 2018 11:32:08 +0100https://ask.sagemath.org/question/41418/what-is-a-possibility-to-tell-sage-to-turn-a-list-into-a-multiset/Answer by slelievre for <p>A well-known computer algebra package features a useful command called 'Tally', which e.g. takes a list like 2,1,2,2,3,1 and returns the list of pairs (1,2),(2,3),(3,1), where the second component of each pair equals the multiplicity of the first component of the pair in the input list. Currently, I am learning more Sage, and I need some functionality like the above. </p>
<p><strong>My question.</strong> Is there a 'native' way to do the same in Sage? Of course, I could program something like this, but what is, in your opinion, the currently 'best' way to turn an arbitrary list into a multiset, with the multiplicities conveniently recorded?</p>
https://ask.sagemath.org/question/41418/what-is-a-possibility-to-tell-sage-to-turn-a-list-into-a-multiset/?answer=41420#post-id-41420See [this answer](https://ask.sagemath.org/question/39677/plotting-a-frequency-chart-from-a-set-of-values/?answer=39684#post-id-39684).Wed, 07 Mar 2018 14:51:22 +0100https://ask.sagemath.org/question/41418/what-is-a-possibility-to-tell-sage-to-turn-a-list-into-a-multiset/?answer=41420#post-id-41420