count 18

Delete occurrences of an element if it occurs more than n times

Description: Enough is enough! Alice and Bob were on a holiday. Both of them took many pictures of the places they've been, and now they want to show Charlie their entire collection. However, Charlie doesn't like these sessions, since the motive usually repeats. He isn't fond of seeing the Eiffel tower 40 times. He tells them that he will only sit during the session if they show the same motive ..

Count characters in your string

문제 설명 The main idea is to count all the occurring characters in a string. If you have a string like aba, then the result should be {'a': 2, 'b': 1}. What if the string is empty? Then the result should be empty object literal, {}. 해결 방법 1. 문자열을 요소별로 반복한다. 2. 문자열과 문자열의 수를 딕셔너리 키 값으로 넣는다. def count(string): dict = {} for i in string: try: dict[i] += 1 except KeyError: dict[i] = 1 return dict if로 풀 ..

Bit Counting

문제 설명 Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative. Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case 해결 방법 1. 들어온 수를 2진수로 바꾼다. 2. 바꾼 수에서 '1'의 개수를 세어 반환한다. def count_bits(n): return bin(n).count('1..