大宮盆栽デイズ - Omiya Bonsai Days -

冗談めかす埼玉のファインマン

CheckiO

@CheckiO@Bird Language

VOWELS = "aeiouy" def translate(phrase): # return phrase human_phrase = [] i = 0 while i < len(phrase): human_phrase.append(phrase[i]) if phrase[i] in VOWELS: i += 3 elif phrase[i] == ' ': i += 1 else: i += 2 return ''.join(human_phrase) i…

@CheckiO@Flatten a List

この問題が属する、「Home」カテゴリがとてもむずかしい。これ以降、あまりにも難しかったら CheckiO から離脱して、なんらかの教本で勉強をしなおそうかな。 def flat_list(array): flatten = [] for x in array: if type(x) is list: flatten.extend(flat_…

@CheckiO@Xs and Os Referee

from typing import List def checkio(game_result: List[str]) -> str: ''' [0][0],[0][1],[0][2] [1][0],[1][1],[1][2] [2][0],[2][1],[2][2] ''' for row in game_result: if row[0] == row[1] == row[2] and row[0] != ".": return row[0] if game_resul…

@CheckiO@The Most Wanted Letter

def checkio(text: str) -> str: #replace this for solution import re letter = [] text = text.lower() for c in text: m = re.match(r'[a-z]', c) if m is None: continue else: letter.append(c) list_zero = [] set_letter = set(letter) length = len…

@CheckiO@Non-unique Elements

# 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…

@CheckiO@House Password

def checkio(data: str) -> bool: # replace this for solution # return True or False import re if len(data) < 10: return False if not bool(re.search(r'[a-z]', data)): return False if not bool(re.search(r'[A-Z]', data)): return False if not b…

@CheckiO@Popular Words

def popular_words(text: str, words: list) -> dict: # 小文字に変換する lower_text = text.lower() # 改行(\n)をスペースに変換する replace_text = lower_text.replace('\n',' ') # 空白を区切りとして文字列をリストに変換する list_text = replace_t…

@CheckiO@Best Stock

def best_stock(data): value_sorted = sorted(data.items(), key=lambda x:x[1]) return value_sorted[-1][0] if __name__ == '__main__': print("Example:") print(best_stock({ 'CAC': 10.0, 'ATX': 390.2, 'WIG': 1.2 })) # These "asserts" are used fo…

@CheckiO@Correct Sentence

def correct_sentence(text: str) -> str: """ returns a corrected sentence which starts with a capital letter and ends with a dot. """ capital_letter = text.capitalize() capital_letter = capital_letter[0] + text[1:] if capital_letter.find('.…

@CheckiO@First Word

def first_word(text: str) -> str: """ returns the first word in a given text. """ # ドットとカンマをスペースに置換する del_conmma = text.replace(',', ' ') del_dot = del_conmma.replace('.', ' ') replaced_text = del_dot # スペースを区切りに…

@CheckiO@Between Markers

答えを出すまでに時間がかかっています。それでも、考えているときは楽しく、(とりあえず)解決コードができたらうれしい気持ちになります。 ◆ ◆ ◆ 時間がかかる、という点でセンスが無いようにも思います。一方で、時間がかかっても粘って取り組むことがで…

@CheckiO@First Word (simplified)

def first_word(text: str) -> str: """ returns the first word in a given text. """ # your code here # return text[0:2] word = '' for c in text: if not c == ' ': word = word + c else: break return word if __name__ == '__main__': print("Examp…

@CheckiO@Between Markers (simplified)

def between_markers(text: str, begin: str, end: str) -> str: """ returns substring between two given markers """ index_begin = text.find(begin) index_end = text.find(end) return text[index_begin+1:index_end] if __name__ == '__main__': prin…

@CheckiO@Multiply (Intro)

def mult_two(a, b): return a * b if __name__ == '__main__': print("Example:") print(mult_two(3, 2)) # These "asserts" are used for self-checking and not for an auto-testing assert mult_two(3, 2) == 6 assert mult_two(1, 0) == 0 print("Codin…

@CheckiO@Second Index

def second_index(text: str, symbol: str) -> [int, None]: """ returns the second index of a symbol in a given text """ index = text.find(symbol) if index != -1: # findの第二引数で検索を開始する位置を指定できる。 index = text.find(symbol, in…

@CheckiO@Say Hi

# 1. on CheckiO your solution should be a function # 2. the function should return the right answer, not print it. def say_hi(name: str, age: int) -> str: """ Hi! """ introduces = "Hi. My name is " + name + " and I'm " + str(age) + " years…

@CheckiO@Bigger Price

def bigger_price(limit: int, data: list) -> list: """ TOP most expensive goods """ length = len(data) for i in range(length): for j in range(i, length): if data[j]['price'] > data[i]['price']: tmp = data[i] data[i] = data[j] data[j] = tmp …

@CheckiO@Easy Unpack

def easy_unpack(elements: tuple) -> tuple: """ returns a tuple with 3 elements - first, third and second to the last """ # your code here elem_first = elements[0] elem_third = elements[2] elem_last = elements[-2] t = elem_first, elem_third…

@CheckiO@Secret Message

def find_message(text: str) -> str: """Find a secret message""" import re s = re.findall('[A-Z]', text) s = ','.join(s) text = s.replace(',','') return str(text) if __name__ == '__main__': print('Example:') print(find_message("How are you?…

@CheckiO@Index Power

def index_power(array: list, n: int) -> int: """ Find Nth power of the element with index N. """ length = len(array) if n+1 > length: return -1 data = array[n] data = data ** n return int(data) if __name__ == '__main__': print('Example:') …

@CheckiO@Fizz Buzz

# Your optional code here # You can import some modules or create additional functions def checkio(number: int) -> str: # Your code here # It's main function. Don't remove this function # It's using for auto-testing and must return a resul…

@CheckiO@Three Words

def checkio(words: str) -> bool: list_words = words.split(' ') length = len(list_words) if length < 3: return False count = 0 for w in list_words: if w.isalpha(): count += 1 if count == 3: return True else: count = 0 return False #These "a…

@CheckiO@The Most Numbers

def checkio(*args): nums = list(args) answer = 0 box = 0 length = len(nums) if length < 1: return 0 for i in range(length): for j in range(i, length): if nums[j] > nums[i]: box = nums[i] nums[i] = nums[j] nums[j] = box answer = nums[0] - n…

@CheckiO@Digits Multiplication

def checkio(number: int) -> int: str_num = str(number) list_num = list(str_num) list_num = [int(s) for s in list_num] products = 1 for i in list_num: if i != 0: products = products * i return products if __name__ == '__main__': print('Exam…

@CheckiO@Even the Last

def checkio(array): """ sums even-indexes elements and multiply at the last """ length = len(array) if length == 0: return 0 sums = array[0] for i in range(1, length): if i % 2 == 0: sums = sums + array[i] value = sums * array[-1] return v…

@CheckiO@Right to Left

def left_join(phrases): """ Join strings and replace "right" to "left" """ text = ','.join(phrases) text = text.replace('right', 'left') return text if __name__ == '__main__': print('Example:') print(left_join(("left", "right", "left", "st…

ラムダを理解するのが難しい@CheckiO@Absolute Sorting

CheckiO が面白すぎて夢中になってしまいます。今回取り組んだワーク(Absolute Sorting)の回答例にlambda(ラムダ)が入っていました。 def checkio(numbers_array: tuple) -> list: return sorted(numbers_array, key=lambda x: abs(x)) #These "asserts"…

CheckiO で PyCharm 使って Python 楽しむ学習

CheckiO というサイトがあります。そのサイトでは、プログラミング言語の「Python」を使ったクイズ(演習問題)があります。最初はブラウザでプレイしていましたが、統合開発環境の PyCharm Education をインストールして遊ぶことにしました。 学ぶだけはな…