mk-toolブログ

エンジニアと家のことをごちゃごちゃと書いてます

2017-09-01から1ヶ月間の記事一覧

【checkio】Roman Numerals(Electronic Station)

【他の人のコード】 def _make_roman_nums(i, v, x): return ['', i, i * 2, i * 3, i + v, v, v + i, v + i * 2, v + i * 3, i + x] <200b> roman_nums = [_make_roman_nums('I', 'V', 'X'), # ones _make_roman_nums('X', 'L', 'C'), # tens _make_roman_n…

【checkio】Pawn Brotherhood(Home)

【他の人の驚きコード】 def safe_pawns(pawns): return sum(str(chr(ord(i[0])-1))+str(int(i[1])-1)in pawns or str(chr(ord(i[0])+1))+str(int(i[1])-1) in pawns for i in pawns) 【自分の書いたコード】 def safe_pawns(pawns): potential_position = […

【checkio】Pawn Brotherhood(Home)

【他の人の驚きコード】 def safe_pawns(pawns): return sum(str(chr(ord(i[0])-1))+str(int(i[1])-1)in pawns or str(chr(ord(i[0])+1))+str(int(i[1])-1) in pawns for i in pawns) < 【自分の書いたコード】 >|python| def safe_pawns(pawns): potential_…

【checkio】Pawn Brotherhood(Home)

def safe_pawns(pawns): potential_position = [] for val in pawns: temp_list = calc_cross(val) potential_position += temp_list count = [i in potential_position for i in pawns].count(True) return count #斜めの位置のコマ位置を計算 def calc_cro…

【Python】str()でエラーが起きてしまう

エラー内容は以下。 TypeError: 'str' object is not callable < 自分でも笑ってしまったが、自身のプログラムの中でstrという変数を宣言していた。strはビルトイン関数のstr()の名前と重複していることが原因みたい。

【Python】True,Falseのカウント

Python3です。[True, True, True, True, True, True, False]のようなリストがあり、 Trueの数を数えたい場合。 count = [True, True, True, True, True, True, False].count(True) print(count)