Zulip Chat Archive

Stream: Is there code for X?

Topic: Frequency distribution of List/Multiset


Tristan Figueroa-Reid (Dec 30 2024 at 07:47):

Is there code for getting an ordered frequency list of elements in a List and/or a Multiset? (Such that some List (7, 7, 7, 3, 3, 3, 3, 4, 7, 4, 4, 7) transforms into (4, 3, 5)).

Yakov Pechersky (Dec 30 2024 at 11:18):

This isn't optimal, but you can use docs#Multiset.count with docs#Multiset.toFinset and docs#Finset.image

Yakov Pechersky (Dec 30 2024 at 11:20):

Not sure what you mean by ordered frequency, and I couldn't figure it out from your example. The list in your example, I would have assumed would give (5, 4, 3) since the first item it encounters is a 7.

Yaël Dillies (Dec 30 2024 at 11:20):

What do you want to do with this frequency distribution? I suspect this is an #xy problem

Yakov Pechersky (Dec 30 2024 at 11:21):

If you want a more conceptual representation, you could use docs#Multiset.toFinsupp

Tristan Figueroa-Reid (Dec 30 2024 at 11:22):

Yakov Pechersky said:

Not sure what you mean by ordered frequency, and I couldn't figure it out from your example. The list in your example, I would have assumed would give (5, 4, 3) since the first item it encounters is a 7.

Oh yes - I mean as it would order the list first then get the frequency of items, though I suppose sorting it first is much better than a specific definition for this.

Yaël Dillies said:

What do you want to do with this frequency distribution? I suspect this is an #xy problem

It might be, but it's for the weight of a semistandard Young Tableau.


Last updated: May 02 2025 at 03:31 UTC