Items3 0118. Ordered Count of Characters 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 impo.. 2023. 1. 18. Find the unique number There is an array with some numbers. All numbers are equal except for one. Try to find it! find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 It’s guaranteed that array contains at least 3 numbers. The tests contain some very huge arrays, so think about performance. Solution: def find_uniq(arr): n = arr[0] == arr[-1] and arr[0] or arr[1] return [i for i in arr if n != i.. 2022. 8. 8. Python _ 딕셔너리 가져오기 메서드 정리 딕셔너리의 get 메서드와 ['키']를 이용해 값을 가져올 수 있습니다. 단 ['키']를 이용해 값을 가져올 경우, 키가 없다면 키 에러를 내뱉으므로 에러를 따로 핸들링 해주어야 합니다. >>> x {'a': 100, 'b': 200, 'c': 300} # x 딕셔너리 키-값 >>> x.get('a') # 'a'키를 가져온다. 100 >>> x.get('d') # 'd', 만약 없는 키를 요청하면 None을 반환한다. >>> >>> type(x.get('d')) >>> x.get('d', 1000) # 없는 키에 두 번째 인자로 기본값을 지정해주면 기본값을 반환한다. 1000 >>> x['a'] # get 뿐만아니라 ['키'] 형태를 이용해 값으르 가져올 수 있다. 100 >>> x['d'] # 단, 이.. 2022. 3. 4. 이전 1 다음