I have list like this:
Pasang = [0, 4, 4, 5, 1, 7, 6, 7, 5, 7, 4, 9, 0, 10, 1, 10,...., 23, 9, 23, 7, 23]
I count item from that list:
satuan = Counter(pasang)
then I get :
Counter({5: 10, 6: 7, 0: 5, 1: 5, 7: 5, 10: 4, 11: 4, 15: 4,...,14: 1, 21: 1})
I want to get key from counter, so i do this:
satu = satuan.keys()
and I get sorted list like this:
[0, 1, 2, 4, 5,...,21, 22, 23]
but I need an output like this (not sorted):
[5, 6, 0, 1,...,14, 21]
Sorry for my bad english.
You probably need:
[key for key, freq in c.most_common()]
where c
is the Counter
instance.
most_common
will return pairs of keys and frequencies, in decreasing order of frequency. Then you extract the key part using a comprehension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With