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.Tue, 08 Sep 2020 10:15:31 +0200How do you sort Beker and Piper characteristic frequencies in order from least common to most common frequency?https://ask.sagemath.org/question/53360/how-do-you-sort-beker-and-piper-characteristic-frequencies-in-order-from-least-common-to-most-common-frequency/ Hello, I am trying to figure out how to sort the characteristic frequency of each letter in the table for beker and piper. I currently only have the code that will output the beker and piper table in order from the alphabet but I was wondering if there is a way to sort them from least to greatest based on their frequency?
Any information helps and here is the code I have so far
N = AlphabeticStrings()
table = N.characteristic_frequency(table_name="beker_piper")
sorted(table.items())Mon, 07 Sep 2020 17:48:23 +0200https://ask.sagemath.org/question/53360/how-do-you-sort-beker-and-piper-characteristic-frequencies-in-order-from-least-common-to-most-common-frequency/Answer by tmonteil for <p>Hello, I am trying to figure out how to sort the characteristic frequency of each letter in the table for beker and piper. I currently only have the code that will output the beker and piper table in order from the alphabet but I was wondering if there is a way to sort them from least to greatest based on their frequency?</p>
<p>Any information helps and here is the code I have so far</p>
<p>N = AlphabeticStrings()</p>
<p>table = N.characteristic_frequency(table_name="beker_piper")</p>
<p>sorted(table.items())</p>
https://ask.sagemath.org/question/53360/how-do-you-sort-beker-and-piper-characteristic-frequencies-in-order-from-least-common-to-most-common-frequency/?answer=53365#post-id-53365You can provide a key function to sort with, as follows (say you want the most frequent letter first):
sage: sorted(table, key=table.get, reverse=True)
['E',
'T',
'A',
'O',
'I',
'N',
'S',
'H',
'R',
'D',
'L',
'C',
'U',
'M',
'W',
'F',
'G',
'Y',
'P',
'B',
'V',
'K',
'J',
'Q',
'X',
'Z']Tue, 08 Sep 2020 10:15:31 +0200https://ask.sagemath.org/question/53360/how-do-you-sort-beker-and-piper-characteristic-frequencies-in-order-from-least-common-to-most-common-frequency/?answer=53365#post-id-53365