본문 바로가기
728x90

프로그래밍 문제53

[Check-IO] Conversion from CamelCase [1] Problem: https://py.checkio.org/en/mission/conversion-from-camelcase/ [2] My solution def from_camel_case(name: str) -> str: #replace this for solution list_str = list(name) for n in range(len(list_str)): if list_str[n].isupper(): if n > 0: list_str[n] = '_' + list_str[n] list_str[n] = list_str[n].lower() return ''.join(list_str) if __name__ == '__main__': print("Example:") print(from_camel_.. 2021. 12. 20.
[Check-IO] The Most Wanted Letter [1] Problem: https://py.checkio.org/en/mission/most-wanted-letter/ [2] My solutions def checkio(text: str) -> str: #replace this for solution text = text.lower() word_list = list(dict.fromkeys(text)) word_dict = {} for word in word_list: if word.isalpha(): word_dict[word] = text.count(word) return sorted(word_dict.items(), key=(lambda x: (-x[1], x[0])))[0][0] if __name__ == '__main__': print("Ex.. 2021. 12. 19.
[Check-IO] Follow Instructions [1] Problems: https://py.checkio.org/en/mission/follow-instructions/ [2] My solutions def follow(instructions: str) -> Tuple[int, int]: # your code here f = instructions.count('f') b = instructions.count('b') l = instructions.count('l') r = instructions.count('r') return (- l + r, -b +f ) [3] Good solutions def follow(instructions): c = instructions.count return c('r') - c('l'), c('f') - c('b') 2021. 12. 18.
[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.
728x90