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

[CheckIO] Popular words Problems: py.checkio.org/en/mission/popular-words/ My solution def popular_words(text: str, words: list) -> dict: # your code here counts = [] for f_word in words: counting_numbers = 0 for match_words in (text.lower()).split(): if match_words == f_word: counting_numbers = counting_numbers + 1 counts.append(counting_numbers) return dict(zip(words, counts)) if __name__ == '__main__': print("Exampl.. 2020. 12. 23.
[CheckIO] non unique elements Problem: py.checkio.org/en/mission/non-unique-elements/ My solution #Your optional code here #You can import some modules or create additional functions def checkio(data: list) -> list: #Your code here #It's main function. Don't remove this function #It's used for auto-testing and must return a result for check. #replace this for solution for number in data[::-1]: if data.count(number) == 1: del.. 2020. 12. 22.
CheckIO - Between Markers Problem: py.checkio.org/en/mission/between-markers/ My solution: def between_markers(text: str, begin: str, end: str) -> str: """ returns substring between two given markers """ # your code here if begin in text and end in text: # condition 1 & condition 5 # condition 1 if text.index(begin) < text.index(end): return text[text.index(begin)+len(begin):text.index(end)] # condition 5 else: return ''.. 2020. 12. 21.
CheckIO - Bigger price Problem: py.checkio.org/en/mission/bigger-price/ My Solution: def bigger_price(limit: int, data: list) -> list: """ TOP most expensive goods """ # your code here return sorted(data, key = (lambda x: x["price"]), reverse = True)[:limit] if __name__ == '__main__': from pprint import pprint print('Example:') pprint(bigger_price(2, [ {"name": "bread", "price": 100}, {"name": "wine", "price": 138}, {.. 2020. 12. 20.
CheckIO - Count digits Problem: py.checkio.org/en/mission/count-digits/ My Solution: def count_digits(text: str) -> int: # your code here count = 0 for n in list(text): if n.isdigit(): count = count + 1 return count if __name__ == '__main__': print("Example:") print(count_digits('hi')) # These "asserts" are used for self-checking and not for an auto-testing assert count_digits('hi') == 0 assert count_digits('who is 1s.. 2020. 12. 14.
CheckIO - Days between Problems: py.checkio.org/en/mission/days-diff/ My solutions from datetime import datetime, timedelta, timezone def days_diff(a, b): # your code here return abs((datetime(a[0],a[1],a[2]) - datetime(b[0], b[1], b[2])).days) if __name__ == '__main__': print("Example:") print(days_diff((1982, 4, 19), (1982, 4, 22))) # These "asserts" are used for self-checking and not for an auto-testing assert days.. 2020. 12. 12.
CheckIO - first word Problem: py.checkio.org/en/mission/first-word/ My Solution; import re def first_word(text: str) -> str: """ returns the first word in a given text. """ # your code here words = re.sub('\.', " ", text) words = re.sub(",", " ", words) return words.split()[0] if __name__ == '__main__': print("Example:") print(first_word("Hello world")) # These "asserts" are used for self-checking and not for an aut.. 2020. 12. 11.
CheckIO - three words Problem: py.checkio.org/en/mission/three-words/ My solution: def checkio(words: str) -> bool: n = 0 for word in words.split(): if word.isalpha() == True: n = n + 1 else: n = 0 if n == 3: break if n == 3: return True else: return False #These "asserts" using only for self-checking and not necessary for auto-testing if __name__ == '__main__': print('Example:') print(checkio("Hello World hello")) a.. 2020. 12. 11.
[CheckIO] Right to Left Problems: py.checkio.org/en/mission/right-to-left/ My solution: import re def left_join(phrases: tuple) -> str: """ Join strings and replace "right" to "left" """ dummy = "" for string in phrases: dummy = dummy + re.sub('right', 'left', string) + "," return dummy[:-1] if __name__ == '__main__': print('Example:') print(left_join(("left", "right", "left", "stop"))) #These "asserts" using only for .. 2020. 12. 9.

0%