23
4
Given a string of printable ASCII, output the frequency of each character in that string.
The Challenge
- Input is given as a string of printable ASCII characters (decimal
[32-126]
inclusive). - Output the frequency of each character, in ASCII order.
- The output must have a format similar to
[character][separator][count]
. Provided that there is a single, non-newline separating string between the character and its frequency, it is a valid output. - Output can be a single string, multiple strings, list of 2-tuples, array of tuples, etc.
- Input and output can be given using any convenient method.
- Standard loopholes are forbidden.
- This is code-golf, so shortest in bytes wins.
Sample I/O
abcd
//outputs
a: 1
b: 1
c: 1
d: 1
Over 9001!
//outputs
[ 1
! [ 1
0 [ 2
1 [ 1
9 [ 1
O [ 1
e [ 1
r [ 1
v [ 1
--<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.
//outputs (as 2-tuples)
(+,14),(-,13),(.,13),(<,21),(>,13),([,2),(],2)
Su3OH39IguWH
//outputs (as 2d array)
[[3,2],[9,1],[H,2],[I,1],[O,1],[S,1],[W,1],[g,1],[u,2]]
Related and related. – bigyihsuan – 2019-07-24T05:00:28.330
7Output the frequency of each character, in ASCII order. but
e
afterv
‽ – Adám – 2019-07-24T06:21:17.9434May I output
a,1b,2c,3
? – tsh – 2019-07-24T07:40:31.237Could I use
– Shaun Bebbers – 2019-07-24T11:48:07.860PETSCII
instead? -> https://www.c64-wiki.com/wiki/PETSCII Also, do you mean trueASCII
(7-bit), or simplyASCII
-compatible, like extendedASCII
orUTF-8
?I assume the output be for
aAbBcCdD
will it beA:1, B:1, C:1, D:1, a:1, b:1 c:1, d:1
- your examples of input/output has a type as Adam has mentioned above. – Shaun Bebbers – 2019-07-24T11:54:37.213You say there is a single character separator yet your first two examples use 2 and 3 character separators. Is the mistake in the spec or the examples? – Post Rock Garf Hunter – 2019-07-24T12:05:18.857
@tsh No, but
a,1 b,2 c,3
is a valid output – bigyihsuan – 2019-07-24T12:43:25.1631@ShaunBebbers ooo that's something. I'll allow it. ASCII-compatibles are also fine, provided you say what encoding it is. – bigyihsuan – 2019-07-24T12:47:51.703
May we assume nonempty input? – Khuldraeseth na'Barya – 2019-07-25T21:18:21.897
@Khuldraesethna'Barya Yes. – bigyihsuan – 2019-07-25T21:20:32.903
Can there be any leading/trailing characters on the output? before the first line or after the last line? – Marie – 2019-07-26T20:18:04.767
@KevinCruijssen Ah-ha, the very challenge I thought of but couldn't find when I saw this in the Sandbox so, in a rare occurrence for me, I'm gonna swing my hammer as I don't think the requirement that the output be sorted makes this significantly different. – Shaggy – 2019-07-26T22:39:45.330