Exploded view of a string
Python 3.5+, 77 46 44 41 bytes
lambda s:[a*s.count(a)for a in{*s}-{' '}]
Pretty simple. Goes through the unique characters in the string by converting it to a set (using Python 3.5's extended iterable unpacking), then uses a list comprehension to construct the exploded diagrams by counting the number of times each character occurs in the string with str.count
. We filter out spaces by removing them from the set.
The order of the output may vary from run to run; sets are unordered, so the order in which their items are processed, and thus this answer outputs, cannot be guaranteed.
This is a lambda expression; to use it, prefix lambda
with f=
.
Try it on Ideone! Ideone uses Python 3.4, which isn't sufficient.
Usage example:
>>> f=lambda s:[a*s.count(a)for a in{*s}-{' '}]
>>> f('Ah, abracadabra!')
[',', 'A', 'aaaaa', 'd', '!', 'bb', 'h', 'c', 'rr']
Saved 3 bytes thanks to @shooqie!
Jelly, 5 bytes
ḟ⁶ṢŒg
Try it online!
It does return an array, just that when it is printed to STDOUT, the separator is gone.
This is indeed a function that can be called as such (in Jelly, each line is a function).
ḟ⁶ṢŒg
ḟ⁶ filter out spaces
Ṣ sort
Œg group
Retina, 13 bytes
O`.
!`(\S)\1*
The sorting is very easy (it's a builtin), it's separating the letters that takes 9 bytes. Try it online!
The first line sO
rts all matches of the regex .
(which is every character), giving us !,Aaaaaabbcdhrr
.
Match is the default stage for the last line of a program, and !
makes it print a linefeed-separated list of matches of the regex. The regex looks for one or more instances of a non-space character in a row.