본문 바로가기
728x90

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

[Check-IO] Common Words [1] Problem: https://py.checkio.org/en/mission/common-words/ [2] My solution def checkio(line1: str, line2: str) -> str: # your code here line1 = line1.split(',') line2 = line2.split(',') result = [] for word in line1: if word in line2: result.append(word) return ",".join(sorted(result)) [3] Best solutions 2021. 12. 16.
[Check-IO] Sum by Type [1] Problem: https://py.checkio.org/en/mission/sum-by-type/ [2] My solution: def sum_by_types(items: list) -> Tuple[str, int]: # your code here first_arg = '' second_arg = 0 for var in items: if isinstance(var, str): first_arg = first_arg + var else: second_arg = second_arg + var return (first_arg, second_arg) [3] Best solution def sum_by_types(items): result = ['', 0] for item in items: result[.. 2021. 12. 12.
[Check-IO] Time converter 1. Problem: https://py.checkio.org/en/mission/time-converter-24h-to-12h/ 2. My solutions def time_converter(time): #replace this for solution hour, minutes = time.split(":") hour = int(hour) if hour > 12 or hour == 12: if hour > 12: hour = hour - 12 day_night = 'p.m.' else: if hour == 0: hour = 12 day_night = 'a.m.' time_string = "%d:%s %s" %(hour, minutes, day_night) return time_string if __nam.. 2021. 12. 10.
[CheckIO] Goes Right After [1] Problem: https://py.checkio.org/en/mission/goes-after/ [2] My solution def goes_after(word: str, first: str, second: str) -> bool: # your code here word_list = list(word) if (first not in word_list) or (second not in word_list): return False if first == second: return False first_index = word_list.index(first) word_list.pop(first_index) second_index = word_list.index(second) if first_index =.. 2021. 12. 3.
[Check-IO] Absolute Sorting [1] Problem: https://py.checkio.org/en/mission/absolute-sorting/ [2] Solution def checkio(values: list) -> list: # your code here abs_sorted = sorted([abs(n) for n in values]) answers = [] for n in range(len(abs_sorted)): if not abs_sorted[n] in values: answers.append(- abs_sorted[n]) else: answers.append(abs_sorted[n]) return answers if __name__ == '__main__': print("Example:") print(checkio([-.. 2021. 11. 14.
[Check-IO] Frequency Sorting Problem: py.checkio.org/en/mission/frequency-sorting/ My Solution def frequency_sorting(numbers): # eliminating duplication of elements in a list, "numbers" # then, sorting its list in ascending order set_list = sorted(list(set(numbers))) # count the number of each elements in "numbers" count = list(map(lambda x: numbers.count(x), set_list)) sorted_set_list = sorted(set_list, key=(lambda x: coun.. 2021. 4. 18.
[CheckIO] Median 1. Problem: py.checkio.org/en/mission/median/ 2. My solution: def checkio(data: List[int]) -> [int, float]: dummy = sorted(data) len_list = len(dummy) # For odd elements if len_list % 2 == 1: return dummy[len_list // 2] # For even elements else: return (dummy[len_list // 2 - 1] + dummy[len_list // 2]) / 2 2021. 3. 23.
[CheckIO] Remove All After 1. Problems : py.checkio.org/en/mission/remove-all-after/ 2. My Solution; def remove_all_after(items: list, border: int) -> Iterable: # your code here return items[:items.index(border) + 1] if border in items else items 2021. 3. 22.
[Check-IO] Lightbulb Intro Problem: py.checkio.org/en/mission/lightbulb-intro/ My solution def sum_light(els: List[datetime]) -> int: """ how long the light bulb has been turned on """ time = 0 for n in range(len(els) // 2): time += (els[2 * n + 1] - els[2*n]).total_seconds() return int(time) 2021. 3. 17.
728x90