CMQ (Python is my preferred language). Given a list of strings, sample one letter with probability proportional to the proportion of times it appears as the first letter of one of the strings
CMQGiven a list of strings, sample one letter with probability proportional to the proportion of times it appears as the first letter of one of the strings and also return the probability of the sampled letter
So ?⍤≢⊃⊢)⊃¨ is equivalent to the previous answer, and ⊢(⊢,+.=÷≢⍤⊣) applies the inner function ⊢,+.=÷≢⍤⊣ with the selected character as right argument and the initials as left argument: ⊢ the selected character , followed by +.= the sum of vectorised equality ÷ divided by ≢ the length ⍤ of ⊣ the initials.
from collections import Counter
words = ["ap", "pear", "aa", "bca", "ppp", "pqr", "pzf"]
c = Counter([word[0] for word in words])
for key in c:
c[key] = c[key]/len(words)
import random
random.choices([*c.keys()], [*c.values()])[0]
actually this should do
from collections import Counter
words = ["ap", "pear", "aa", "bca", "ppp", "pqr", "pzf"]
c = Counter([word[0] for word in words])
import random
random.choices([*c.keys()], [*c.values()])[0]
@att Yeah. :( If you still want to learn you a Haskell, reading through the chat transcript might be enlightening, and we also unfroze the Haskell room.