반응형
Count the number of occurrences of each character and return it as a (list of tuples) in order of appearance. For empty output return (an empty list).
Consult the solution set-up for the exact data structure implementation depending on your language.
Example:
ordered_count("abracadabra") == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)]
Solution:
def ordered_count(inp):
from collections import Counter
count_dict = Counter(list(inp))
return [tuple for tuple in zip(count_dict.keys(), count_dict.values())]
from collections import Counter
def ordered_count(inp):
return list(Counter(inp).items())
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0120. Alphabet symmetry (0) | 2023.01.21 |
---|---|
0119. Thinkful - Number Drills: Blue and red marbles (0) | 2023.01.19 |
0117. get character from ASCII Value (0) | 2023.01.18 |
0116. OOP: Object Oriented Piracy (0) | 2023.01.16 |
0115. Name on billboard (0) | 2023.01.15 |