본문 바로가기
728x90

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

[CheckIO/Scientific Expedition] Longest substring of unique characters 1. Problem : https://py.checkio.org/en/mission/longest-substring-of-unique-characters/ 2. My solution def longest_substr(s: str) -> int: # your code here no_repeat_list = [] longest = 0 for char in [*s]: if no_repeat_list.count(char) == 0: no_repeat_list.append(char) else: index = no_repeat_list.index(char)+1 no_repeat_list.append(char) no_repeat_list = no_repeat_list[index:] if len(no_repeat_li.. 2024. 2. 18.
[CheckIO] Replace All Occureences 1. Problem: https://py.checkio.org/en/mission/replace-all-occurrences/ 2. My solutions def replace_all(mainText: str, target: str, repl: str) -> str: # your code here return mainText.replace(target, repl) 2024. 2. 18.
[CheckIO] Convert To Title case 1. Problem: https://py.checkio.org/en/mission/convert-to-title-case/ 2. My solutions def to_title_case(sentence: str) -> str: # your code here return ' '.join([data.capitalize() for data in sentence.lower().split()]) print("Example:") print(to_title_case("hello world")) # These "asserts" are used for self-checking assert to_title_case("hello world") == "Hello World" assert to_title_case("openai .. 2024. 2. 18.
[CheckIO] Count Vowels 1. Problem: https://py.checkio.org/en/mission/count-vowels/ 2. My solutions def count_vowels(text: str) -> int: # your code here number_vowels = 0 lower_case = text.lower() for vowel in ['a','e','o','i', 'u']: number_vowels += [*lower_case].count(vowel) print(number_vowels) return number_vowels print("Example:") #print(count_vowels("Hello")) # These "asserts" are used for self-checking assert co.. 2024. 2. 18.
[Check IO] words-order 1. Problem: https://py.checkio.org/en/mission/words-order/ 2. My solutions def words_order(text: str, words: list) -> bool: # your code here original_list = text.split() # check that words is in text for word in words: if word not in original_list: return False if words.count(word) != 1: return False order = list(map(lambda x: original_list.index(x), words)) if order == sorted(order): return Tru.. 2022. 2. 27.
[Check-IO] Conversion into CamelCase [1] Problem: https://py.checkio.org/en/mission/conversion-into-camelcase/ [2] My solutions def to_camel_case(name: str) -> str: #replace this for solution dummy_list = list(map(lambda x: x.capitalize(), name.split('_'))) return "".join(dummy_list) if __name__ == '__main__': print("Example:") print(to_camel_case('name')) #These "asserts" using only for self-checking and not necessary for auto-tes.. 2021. 12. 25.
[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.
728x90