본문 바로가기
728x90

프로그래밍 문제/[Python] CheckIO50

[CheckIO] Majority Problem: py.checkio.org/en/mission/majority/ My Solution: def is_majority(items: list) -> bool: # your code here return True if items.count(True) > items.count(False) else False if __name__ == '__main__': print("Example:") print(is_majority([True, True, False, True, False])) # These "asserts" are used for self-checking and not for an auto-testing assert is_majority([True, True, False, True, Fals.. 2021. 3. 11.
[CheckIO] Backward Each Word Problem: py.checkio.org/en/mission/backward-each-word/ My solution: def backward_string_by_word(text: str) -> str: # your code here words_list = text.split() # list1 = list(text) # character list that would be substituted by reversed words list2 = list(text) # dummy list that is used to find an index of a word in the list for word in words_list: dummy_str = "".join(list2) # index = dummy_str.fin.. 2021. 3. 10.
[Check-IO] Morse Decoder Problem: py.checkio.org/en/mission/morse-decoder/ My solution: MORSE = {'.-': 'a', '-...': 'b', '-.-.': 'c', '-..': 'd', '.': 'e', '..-.': 'f', '--.': 'g', '....': 'h', '..': 'i', '.---': 'j', '-.-': 'k', '.-..': 'l', '--': 'm', '-.': 'n', '---': 'o', '.--.': 'p', '--.-': 'q', '.-.': 'r', '...': 's', '-': 't', '..-': 'u', '...-': 'v', '.--': 'w', '-..-': 'x', '-.--': 'y', '--..': 'z', '-----': '.. 2021. 3. 8.
[CheckIO] Solve All the same Problems: py.checkio.org/en/mission/all-the-same/ My solution from typing import List, Any def all_the_same(elements: List[Any]) -> bool: # your code here if len(set(elements)) == 1 or len(set(elements)) == 0: return True else: return False if __name__ == '__main__': print("Example:") print(all_the_same([1, 1, 1])) # These "asserts" are used for self-checking and not for an auto-testing assert a.. 2021. 1. 7.
[CheckIO] Solve split list Problem: py.checkio.org/en/mission/split-list/ My solution def split_list(items: list) -> list: # your code here length = len(items) if length % 2 == 0: return [items[:length//2],items[length//2:]] else: return [items[:length//2+1],items[length//2+1:]] if __name__ == '__main__': print("Example:") print(split_list([1, 2, 3, 4, 5, 6])) # These "asserts" are used for self-checking and not for an au.. 2021. 1. 5.
[CheckIO] Sun angle Problem: py.checkio.org/en/mission/sun-angle/ My Solution def sun_angle(time): #replace this for solution hour, min = map(int,time.split(':')) def angle_from_the_sun(hour, min): degree_per_min = float(360 / (60*24)) time = 60 * (hour - 6) + min return round(degree_per_min * time, 2) if (6 2021. 1. 3.
[CheckIO] pawn-brotherhood Problems: py.checkio.org/en/mission/pawn-brotherhood/ My solution: def safe_pawns(pawns: set) -> int: position_data = list(pawns) def check_safe(position): x,y = list(position) defence_x1 = chr(ord(x) - 1) defence_x2 = chr(ord(x) + 1) defence_y = int(y) - 1 defence_pos1 = defence_x1 + str(defence_y) defence_pos2 = defence_x2 + str(defence_y) if defence_pos1 in pawns or defence_pos2 in pawns: ret.. 2021. 1. 2.
[CheckIO] sort array by element frequency Problems: py.checkio.org/en/mission/sort-array-by-element-frequency/ My Solution: def frequency_sort(items): # your code here count_value = dict.fromkeys(items) count_list = [items.count(x) for x in count_value] dict_list = dict(zip(count_value, count_list)) sort_list = dict(sorted(dict_list.items(), key = (lambda x: x[1]), reverse=True)) new_list = [] for x in sort_list: new_list.extend([x for .. 2020. 12. 30.
[CheckIO] Second Index Problem: py.checkio.org/en/mission/second-index/ My Solution def second_index(text: str, symbol: str) -> [int, None]: """ returns the second index of a symbol in a given text """ # your code here m = 0 for n in range(len(list(text))): if list(text)[n] == symbol: if m == 1: return n else: m = m + 1 return None if __name__ == '__main__': print('Example:') print(second_index("sims", "s")) # These ".. 2020. 12. 24.
728x90