SlideShare a Scribd company logo
1 of 93
Download to read offline
Python



                momo_*(        tututen)
                           1
2011   7   30
2
2011   7   30
•
                • Python
                •
                •          C


                               3
2011   7   30
←→   294km
                         4
2011   7   30
•
       •
            •
            •

                5
2011   7   30
ATTENTION

                    6
2011   7   30
•              PEP8



                • Python
                • Python

                •
                           7
2011   7   30
8
2011   7   30
•


                    9
2011   7   30
•
                •
                    (   )
                            (hatena keyword   )

                            10
2011   7   30
•
                •
                    (   )
                            (hatena keyword   )

                •                   wiki
                            11
2011   7   30
Python



                   12
2011   7   30
Python




                         (wikipedia   )
                              13
2011   7   30
14
2011   7   30
15
2011   7   30
• range(0, max_value, 2)




                                     16
2011   7   30
• range(0, max_value, 2)
                • [i * 2 for i in range(num)]




                                      17
2011   7   30
• range(0, max_value, 2)
                • [i * 2 for i in range(num)]
                • a = []
                  for i in range(num):
                     a.append(i * 2)




                                         18
2011   7   30
19
2011   7   30
20
2011   7   30
3



                    21
2011   7   30
3
                •       OX

                •
                    •
                    •
                    •
                                 22
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   23
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   24
2011   7   30
25
2011   7   30
•
                •   1   2

                •


                            26
2011   7   30
•
                •   1   2

                    ‣   1

                •


                            27
2011   7   30
•
                •   1   2

                    ‣   1

                •
                    ‣

                            28
2011   7   30
• field = []
                  for i in range(9):
                     field.append(‘_‘)




                                   29
2011   7   30
• field = []
                  for i in range(9):
                     field.append(‘_‘)
                • field = [‘_‘ for i in range(9)]


                                    30
2011   7   30
• field = []
                  for i in range(9):
                     field.append(‘_‘)
                • field = [‘_‘ for i in range(9)]
                • field = [‘_‘] * 9

                                    31
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   32
2011   7   30
33
2011   7   30
•
                • O or X
                  ‣ −

                           34
2011   7   30
• turn = 1
                  for x range(3):
                      for y range(3):
                         print field[x + y * 3],
                      print ‘’
                  if turn == 1:
                      print ‘o turn’
                  else :
                      print ‘x turn’

                                     35
2011   7   30
• turn = 1
                  for x range(3):
                      for y range(3):
                         print field[x + y * 3],
                      print ‘’
                  if turn == 1:
                      print ‘o turn’
                  else :
                      print ‘x turn’

                                     36
2011   7   30
• turn = 1
                  print “%s%s%s¥n%s%s%s¥n%s%s%s”
                      % tuple(field)
                  if turn == 1:
                      print ‘o turn’
                  else :
                      print ‘x turn’



                                37
2011   7   30
• turn = 1
                  print “%s%s%s¥n%s%s%s¥n%s%s%s”
                      % tuple(field)
                  if turn == 1:
                      print ‘o turn’
                  else :
                      print ‘x turn’



                                38
2011   7   30
• turn = 1
                  print “%s%s%s¥n%s%s%s¥n%s%s%s”
                     % tuple(field)
                  marks = ‘_ox’
                  print ‘%s turn’ % marks[turn]


                 ✴marks[1] == ‘o’
                 ✴marks[-1] == marks[2] == ‘x’
                                39
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   40
2011   7   30
41
2011   7   30
• raw_input   OK

                • int
                •
                •
                    0<=x<=2    0<=y<=2

                                   42
2011   7   30
• while(True):
                     try:
                         x = int(raw_input(‘x(0-2) -> ‘))
                         y = int(raw_input(‘y(0-2) -> ‘))
                     except:
                         continue
                     if 0 <= x <= 2 and 0 <= y <= 2:
                         break


                                      43
2011   7   30
• while(True):
                     try:
                         x = int(raw_input(‘x(0-2) -> ‘))
                         y = int(raw_input(‘y(0-2) -> ‘))
                     except:
                         continue
                     if 0 <= x <= 2 and 0 <= y <= 2:
                         break


                                      44
2011   7   30
• while(True):
                     inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                     x, y = inp(‘x’), inp(‘y’)
                     try:
                         x = int(x)
                         y = int(y)
                     except:
                         continue
                     vr = lambda n: 0 <= n <= 2
                     if vr(x) and vr(y):
                         break           45
2011   7   30
• while(True):
                     inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                     x, y = inp(‘x’), inp(‘y’)
                     vr = lambda n: 0 <= n <= 2
                     if vr(x) and vr(y):
                         break
                     try:
                         x = int(x)
                         y = int(y)
                     except:
                         continue       46
2011   7   30
• while(True):
                     inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                     x, y = inp(‘x’), inp(‘y’)
                     vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’
                     if vr(x) and vr(y):
                         break
                  try:
                     x = int(x)
                     y = int(y)
                  except:
                     continue           47
2011   7   30
• while(True):
                     inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                     x, y = inp(‘x’), inp(‘y’)
                     vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’
                     if vr(x) and vr(y):
                         break
                  try:
                     x = int(x)
                     y = int(y)
                  except:
                     continue           48
2011   7   30
• while(True):
                     inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                     x, y = inp(‘x’), inp(‘y’)
                     vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’
                     if vr(x) and vr(y):
                         break
                  x, y = int(x), int(y)



                                     49
2011   7   30
• inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                  vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’
                  while(True):
                     x, y = inp(‘x’), inp(‘y’)
                     if vr(x) and vr(y):
                         break
                  x, y = int(x), int(y)



                                     50
2011   7   30
• while(True):
                     try:
                         x = int(raw_input(‘x(0-2) -> ‘))
                         y = int(raw_input(‘y(0-2) -> ‘))
                     except:
                         continue
                     if 0 <= x <= 2 and 0 <= y <= 2:
                         break


                                      51
2011   7   30
• inp = lambda n: raw_input(‘%s(0-2) -> ‘%n)
                  vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’
                  while(True):
                     x, y = inp(‘x’), inp(‘y’)
                     if vr(x) and vr(y):
                         break
                  x, y = int(x), int(y)



                                     52
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   53
2011   7   30
O or X


                         54
2011   7   30
•
                •


                    55
2011   7   30
• if field[x + y * 3] != ‘_’:
                     continue




                                        56
2011   7   30
• if field[x + y * 3] != ‘_’:
                       continue
                •
                    if field[x + y * 3] - ‘_’: continue




                                         57
2011   7   30
• if field[x + y * 3] != ‘_’:
                       continue
                •
                    if field[x + y * 3] - ‘_’: continue




                •
                                         58
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   59
2011   7   30
60
2011   7   30
•8   3

                •


                         61
2011   7   30
•8        3

                •

                •
                     OX


                              62
2011   7   30
•
                    0   1   2


                    3   4   5


                    6   7   8

                                63
2011   7   30
•
                    0   1   2
                                     n,n+1,n+2


                    3   4   5
                                     n,n+3,n+6

                    6   7   8
                                        ????
                                64
2011   7   30
•
                    0   1   2
                                     n,n+1,n+2


                    3   4   5
                                     n,n+3,n+6

                    6   7   8
                                        ????
                                65
2011   7   30
•
                    0   1   2
                                      n,4,8-n

                    3   4   5
                                     n,n+1,n+2
                    6   7   8
                                     n,n+3,n+6
                                66
2011   7   30
•
                    0   1   2
                                      n,4,8-n

                    3   4   5
                                     n,n+1,n+2
                    6   7   8
                                     n,n+3,n+6
                                67
2011   7   30
•
                                      n,4,8-n
                    0   1   2


                    3   4   5        n,n+1,n+2


                    6   7   8
                                     n,n+3,n+6
                                68
2011   7   30
• for i in range(3):
                        if (field[i] != ‘_’ and
                            field[i] == field[i + 1] and
                            field[i] == field[i + 2]):
                            judge = True
                        if (field[4] != ‘_’ and
                            field[4] == field[i] and
                            field[4] == field[8 - i]):
                            judge = True
                  ...
                                         69
2011   7   30
• for i in range(3):
                        if (field[i] != ‘_’ and
                            field[i] == field[i + 1] and
                            field[i] == field[i + 2]):
                            judge = True
                        if (field[4] != ‘_’ and
                            field[4] == field[i] and
                            field[4] == field[8 - i]):
                            judge = True
                  ...
                                         70
2011   7   30
• mark = ‘ ox’[turn]
                  for i in range(3):
                      if [mark]*3 == [field[i], field[i+1],field[i+2]]:
                          judge = True
                      if [mark]*3 == [field[i],field[4],field[8-i]]:
                          judge = True
                      if [mark]*3 == [field[i], field[i+3],field[i+6]]:
                          judge = True
                  ...

                                       71
2011   7   30
• mark = ‘ ox’[turn]
                  jl = lambda line: [mark]*3 == line
                  for i in range(3):
                      if jl([field[i], field[i+1],field[i+2]]):
                           judge = True
                      if jl([field[i],field[4],field[8-i]]):
                           judge = True
                      if jl([field[i], field[i+3],field[i+6]]):
                           judge = True
                  ...
                                        72
2011   7   30
• mark = ‘ ox’[turn]
                  jl = lambda line: [mark]*3 == line
                  for i in range(3):
                      if jl([field[i], field[i+1],field[i+2]]):
                           judge = True
                      if jl([field[i],field[4],field[8-i]]):
                           judge = True
                      if jl([field[i], field[i+3],field[i+6]]):
                           judge = True
                  ...
                                        73
2011   7   30
• mark = ‘ ox’[turn]
                  jl = lambda line: [mark]*3 == line
                  for i in range(3):
                      if jl(field[i*3:i*3+3]):
                           judge = True
                      if jl(field[i:9-i:4-i]):
                           judge = True
                      if jl(field[i::3]):
                           judge = True

                                       74
2011   7   30
• mark = ‘ ox’[turn]
                  jl = lambda line: [mark]*3 == line
                  judge = False
                  for i in range(3):
                      judge = judge or jl(field[i*3:i*3+3])
                      judge = judge or jl(field[i:9-i:4-i])
                      judge = judge or jl(field[i::3])



                                       75
2011   7   30
3
                •
                •
                •
                •        O or X
                •
                •
                •
                •   76
2011   7   30
77
2011   7   30
• for   if




                         78
2011   7   30
• for   if



                •             Pythonista




                         79
2011   7   30
• space_flag = False
                  for val in field:
                      if val == ‘_’:
                          space_flag = True
                  if not space_flag:
                      break




                                      80
2011   7   30
• space_flag = False
                  for val in field:
                      if val == ‘_’:
                          space_flag = True
                  if not space_flag:
                      break




                                      81
2011   7   30
• space_flag = False
                  for val in field:
                      if val == ‘_’:
                          space_flag = True
                  if not space_flag:
                      break


                • if not ‘_’ in field:
                      break
                                        82
2011   7   30
83
2011   7   30
•

                •
                    ‣ turn*=-1
                    ‣ turn=-turn
                                   84
2011   7   30
•
                •
                    ‣ turn*=-1
                    ‣ turn=-turn
                    ‣ t*=-1
                    ‣ t=-t
                                   85
2011   7   30
86
2011   7   30
• judge

                •              mark




                          87
2011   7   30
• if judge:
                     print ‘%s win’ % mark
                  else:
                     print ‘draw’




                                     88
2011   7   30
• if judge:
                     print ‘%s win’ % mark
                  else:
                     print ‘draw’


                • print (‘%s win’ % mark) if judge else ‘draw’

                                      89
2011   7   30
•   Python




                     90
2011   7   30
•   Python




                •


                     91
2011   7   30
•   Python




                •

                •
                     92
2011   7   30
Fin



                 93
2011   7   30

More Related Content

What's hot

X2 T07 02 transformations (2011)
X2 T07 02 transformations (2011)X2 T07 02 transformations (2011)
X2 T07 02 transformations (2011)Nigel Simmons
 
Statistics lecture 13 (chapter 13)
Statistics lecture 13 (chapter 13)Statistics lecture 13 (chapter 13)
Statistics lecture 13 (chapter 13)jillmitchell8778
 
1050 text-ef
1050 text-ef1050 text-ef
1050 text-efsupoteta
 
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part I
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part INon-Gaussian Methods for Learning Linear Structural Equation Models: Part I
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part IShiga University, RIKEN
 
Nonlinear Filtering and Path Integral Method (Paper Review)
Nonlinear Filtering and Path Integral Method (Paper Review)Nonlinear Filtering and Path Integral Method (Paper Review)
Nonlinear Filtering and Path Integral Method (Paper Review)Kohta Ishikawa
 
Non-Gaussian structural equation models for causal discovery
Non-Gaussian structural equation models for causal discoveryNon-Gaussian structural equation models for causal discovery
Non-Gaussian structural equation models for causal discoveryShiga University, RIKEN
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game DesignTrieu Nguyen
 
Growth driven dynamics in mean-field models of interacting spins
Growth driven dynamics in mean-field models of interacting spinsGrowth driven dynamics in mean-field models of interacting spins
Growth driven dynamics in mean-field models of interacting spinsrichardgmorris
 

What's hot (12)

X2 T07 02 transformations (2011)
X2 T07 02 transformations (2011)X2 T07 02 transformations (2011)
X2 T07 02 transformations (2011)
 
Statistics lecture 13 (chapter 13)
Statistics lecture 13 (chapter 13)Statistics lecture 13 (chapter 13)
Statistics lecture 13 (chapter 13)
 
1050 text-ef
1050 text-ef1050 text-ef
1050 text-ef
 
Lesson 1: Functions
Lesson 1: FunctionsLesson 1: Functions
Lesson 1: Functions
 
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part I
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part INon-Gaussian Methods for Learning Linear Structural Equation Models: Part I
Non-Gaussian Methods for Learning Linear Structural Equation Models: Part I
 
Nonlinear Filtering and Path Integral Method (Paper Review)
Nonlinear Filtering and Path Integral Method (Paper Review)Nonlinear Filtering and Path Integral Method (Paper Review)
Nonlinear Filtering and Path Integral Method (Paper Review)
 
Non-Gaussian structural equation models for causal discovery
Non-Gaussian structural equation models for causal discoveryNon-Gaussian structural equation models for causal discovery
Non-Gaussian structural equation models for causal discovery
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game Design
 
QMT202/SET2
QMT202/SET2QMT202/SET2
QMT202/SET2
 
BS1501 tutorial 2
BS1501 tutorial 2BS1501 tutorial 2
BS1501 tutorial 2
 
Lesson 22: Graphing
Lesson 22: GraphingLesson 22: Graphing
Lesson 22: Graphing
 
Growth driven dynamics in mean-field models of interacting spins
Growth driven dynamics in mean-field models of interacting spinsGrowth driven dynamics in mean-field models of interacting spins
Growth driven dynamics in mean-field models of interacting spins
 

More from Fumihito Yokoyama

Aws その他の概要と勘所
Aws その他の概要と勘所Aws その他の概要と勘所
Aws その他の概要と勘所Fumihito Yokoyama
 
Aws lambdaで[ソンナコ]を実装してみた
Aws lambdaで[ソンナコ]を実装してみたAws lambdaで[ソンナコ]を実装してみた
Aws lambdaで[ソンナコ]を実装してみたFumihito Yokoyama
 
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察re:Inventで発表されたAWS Lambdaの更新情報と使い方考察
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察Fumihito Yokoyama
 
今年やってきた中で書いてきたコード
今年やってきた中で書いてきたコード今年やってきた中で書いてきたコード
今年やってきた中で書いてきたコードFumihito Yokoyama
 
制約をつけて遊ぼう
制約をつけて遊ぼう制約をつけて遊ぼう
制約をつけて遊ぼうFumihito Yokoyama
 
Ohotech特盛 #11 Box2DWebを触ってみよう
Ohotech特盛 #11 Box2DWebを触ってみようOhotech特盛 #11 Box2DWebを触ってみよう
Ohotech特盛 #11 Box2DWebを触ってみようFumihito Yokoyama
 
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」Fumihito Yokoyama
 
投げ銭Boxのwebクライアントを作ってみた
投げ銭Boxのwebクライアントを作ってみた投げ銭Boxのwebクライアントを作ってみた
投げ銭Boxのwebクライアントを作ってみたFumihito Yokoyama
 
Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介Fumihito Yokoyama
 
Ohotech 特盛#5 長距離運転の考察ver2
Ohotech 特盛#5 長距離運転の考察ver2Ohotech 特盛#5 長距離運転の考察ver2
Ohotech 特盛#5 長距離運転の考察ver2Fumihito Yokoyama
 
Code jp2013で行った ショートコーディング について
Code jp2013で行った ショートコーディング についてCode jp2013で行った ショートコーディング について
Code jp2013で行った ショートコーディング についてFumihito Yokoyama
 
リバーシの条件判定をlinqで
リバーシの条件判定をlinqでリバーシの条件判定をlinqで
リバーシの条件判定をlinqでFumihito Yokoyama
 
Clrh81 windowsで定期的にキャプチャするために
Clrh81 windowsで定期的にキャプチャするためにClrh81 windowsで定期的にキャプチャするために
Clrh81 windowsで定期的にキャプチャするためにFumihito Yokoyama
 
monoを使ってlt countdowntimerを動かしてみる
monoを使ってlt countdowntimerを動かしてみるmonoを使ってlt countdowntimerを動かしてみる
monoを使ってlt countdowntimerを動かしてみるFumihito Yokoyama
 
密着!わたしのコンソールアプリ開発環境
密着!わたしのコンソールアプリ開発環境密着!わたしのコンソールアプリ開発環境
密着!わたしのコンソールアプリ開発環境Fumihito Yokoyama
 
LINQ を使ったナンプレの解法を作ったお話
LINQ を使ったナンプレの解法を作ったお話LINQ を使ったナンプレの解法を作ったお話
LINQ を使ったナンプレの解法を作ったお話Fumihito Yokoyama
 
Ldd kitami(宣伝用 clrh70)
Ldd kitami(宣伝用 clrh70)Ldd kitami(宣伝用 clrh70)
Ldd kitami(宣伝用 clrh70)Fumihito Yokoyama
 

More from Fumihito Yokoyama (20)

Aws その他の概要と勘所
Aws その他の概要と勘所Aws その他の概要と勘所
Aws その他の概要と勘所
 
Aws lambdaで[ソンナコ]を実装してみた
Aws lambdaで[ソンナコ]を実装してみたAws lambdaで[ソンナコ]を実装してみた
Aws lambdaで[ソンナコ]を実装してみた
 
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察re:Inventで発表されたAWS Lambdaの更新情報と使い方考察
re:Inventで発表されたAWS Lambdaの更新情報と使い方考察
 
今年やってきた中で書いてきたコード
今年やってきた中で書いてきたコード今年やってきた中で書いてきたコード
今年やってきた中で書いてきたコード
 
制約をつけて遊ぼう
制約をつけて遊ぼう制約をつけて遊ぼう
制約をつけて遊ぼう
 
Ohotech特盛 #11 Box2DWebを触ってみよう
Ohotech特盛 #11 Box2DWebを触ってみようOhotech特盛 #11 Box2DWebを触ってみよう
Ohotech特盛 #11 Box2DWebを触ってみよう
 
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」
Osc2014 聞くだけじゃもったいない!観客と発表者の双方向通信を実現する「投げ銭box」
 
投げ銭Boxのwebクライアントを作ってみた
投げ銭Boxのwebクライアントを作ってみた投げ銭Boxのwebクライアントを作ってみた
投げ銭Boxのwebクライアントを作ってみた
 
Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介
 
Ohotech 特盛#5 長距離運転の考察ver2
Ohotech 特盛#5 長距離運転の考察ver2Ohotech 特盛#5 長距離運転の考察ver2
Ohotech 特盛#5 長距離運転の考察ver2
 
Code jp2013で行った ショートコーディング について
Code jp2013で行った ショートコーディング についてCode jp2013で行った ショートコーディング について
Code jp2013で行った ショートコーディング について
 
長距離運転の考察
長距離運転の考察長距離運転の考察
長距離運転の考察
 
リバーシの条件判定をlinqで
リバーシの条件判定をlinqでリバーシの条件判定をlinqで
リバーシの条件判定をlinqで
 
Clrh81 windowsで定期的にキャプチャするために
Clrh81 windowsで定期的にキャプチャするためにClrh81 windowsで定期的にキャプチャするために
Clrh81 windowsで定期的にキャプチャするために
 
monoを使ってlt countdowntimerを動かしてみる
monoを使ってlt countdowntimerを動かしてみるmonoを使ってlt countdowntimerを動かしてみる
monoを使ってlt countdowntimerを動かしてみる
 
密着!わたしのコンソールアプリ開発環境
密着!わたしのコンソールアプリ開発環境密着!わたしのコンソールアプリ開発環境
密着!わたしのコンソールアプリ開発環境
 
Linqで画像処理
Linqで画像処理Linqで画像処理
Linqで画像処理
 
LINQ を使ったナンプレの解法を作ったお話
LINQ を使ったナンプレの解法を作ったお話LINQ を使ったナンプレの解法を作ったお話
LINQ を使ったナンプレの解法を作ったお話
 
Ldd kitami(宣伝用 clrh70)
Ldd kitami(宣伝用 clrh70)Ldd kitami(宣伝用 clrh70)
Ldd kitami(宣伝用 clrh70)
 
関数型忘年会Lt用
関数型忘年会Lt用関数型忘年会Lt用
関数型忘年会Lt用
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Pysap#3.1 Pythonでショートコーディング

  • 1. Python momo_*( tututen) 1 2011 7 30
  • 2. 2 2011 7 30
  • 3. • Python • • C 3 2011 7 30
  • 4. ←→ 294km 4 2011 7 30
  • 5. • • • 5 2011 7 30
  • 6. ATTENTION 6 2011 7 30
  • 7. PEP8 • Python • Python • 7 2011 7 30
  • 8. 8 2011 7 30
  • 9. 9 2011 7 30
  • 10. • ( ) (hatena keyword ) 10 2011 7 30
  • 11. • ( ) (hatena keyword ) • wiki 11 2011 7 30
  • 12. Python 12 2011 7 30
  • 13. Python (wikipedia ) 13 2011 7 30
  • 14. 14 2011 7 30
  • 15. 15 2011 7 30
  • 16. • range(0, max_value, 2) 16 2011 7 30
  • 17. • range(0, max_value, 2) • [i * 2 for i in range(num)] 17 2011 7 30
  • 18. • range(0, max_value, 2) • [i * 2 for i in range(num)] • a = [] for i in range(num): a.append(i * 2) 18 2011 7 30
  • 19. 19 2011 7 30
  • 20. 20 2011 7 30
  • 21. 3 21 2011 7 30
  • 22. 3 • OX • • • • 22 2011 7 30
  • 23. 3 • • • • O or X • • • • 23 2011 7 30
  • 24. 3 • • • • O or X • • • • 24 2011 7 30
  • 25. 25 2011 7 30
  • 26. • 1 2 • 26 2011 7 30
  • 27. • 1 2 ‣ 1 • 27 2011 7 30
  • 28. • 1 2 ‣ 1 • ‣ 28 2011 7 30
  • 29. • field = [] for i in range(9): field.append(‘_‘) 29 2011 7 30
  • 30. • field = [] for i in range(9): field.append(‘_‘) • field = [‘_‘ for i in range(9)] 30 2011 7 30
  • 31. • field = [] for i in range(9): field.append(‘_‘) • field = [‘_‘ for i in range(9)] • field = [‘_‘] * 9 31 2011 7 30
  • 32. 3 • • • • O or X • • • • 32 2011 7 30
  • 33. 33 2011 7 30
  • 34. • O or X ‣ − 34 2011 7 30
  • 35. • turn = 1 for x range(3): for y range(3): print field[x + y * 3], print ‘’ if turn == 1: print ‘o turn’ else : print ‘x turn’ 35 2011 7 30
  • 36. • turn = 1 for x range(3): for y range(3): print field[x + y * 3], print ‘’ if turn == 1: print ‘o turn’ else : print ‘x turn’ 36 2011 7 30
  • 37. • turn = 1 print “%s%s%s¥n%s%s%s¥n%s%s%s” % tuple(field) if turn == 1: print ‘o turn’ else : print ‘x turn’ 37 2011 7 30
  • 38. • turn = 1 print “%s%s%s¥n%s%s%s¥n%s%s%s” % tuple(field) if turn == 1: print ‘o turn’ else : print ‘x turn’ 38 2011 7 30
  • 39. • turn = 1 print “%s%s%s¥n%s%s%s¥n%s%s%s” % tuple(field) marks = ‘_ox’ print ‘%s turn’ % marks[turn] ✴marks[1] == ‘o’ ✴marks[-1] == marks[2] == ‘x’ 39 2011 7 30
  • 40. 3 • • • • O or X • • • • 40 2011 7 30
  • 41. 41 2011 7 30
  • 42. • raw_input OK • int • • 0<=x<=2 0<=y<=2 42 2011 7 30
  • 43. • while(True): try: x = int(raw_input(‘x(0-2) -> ‘)) y = int(raw_input(‘y(0-2) -> ‘)) except: continue if 0 <= x <= 2 and 0 <= y <= 2: break 43 2011 7 30
  • 44. • while(True): try: x = int(raw_input(‘x(0-2) -> ‘)) y = int(raw_input(‘y(0-2) -> ‘)) except: continue if 0 <= x <= 2 and 0 <= y <= 2: break 44 2011 7 30
  • 45. • while(True): inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) x, y = inp(‘x’), inp(‘y’) try: x = int(x) y = int(y) except: continue vr = lambda n: 0 <= n <= 2 if vr(x) and vr(y): break 45 2011 7 30
  • 46. • while(True): inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) x, y = inp(‘x’), inp(‘y’) vr = lambda n: 0 <= n <= 2 if vr(x) and vr(y): break try: x = int(x) y = int(y) except: continue 46 2011 7 30
  • 47. • while(True): inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) x, y = inp(‘x’), inp(‘y’) vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’ if vr(x) and vr(y): break try: x = int(x) y = int(y) except: continue 47 2011 7 30
  • 48. • while(True): inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) x, y = inp(‘x’), inp(‘y’) vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’ if vr(x) and vr(y): break try: x = int(x) y = int(y) except: continue 48 2011 7 30
  • 49. • while(True): inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) x, y = inp(‘x’), inp(‘y’) vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’ if vr(x) and vr(y): break x, y = int(x), int(y) 49 2011 7 30
  • 50. • inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’ while(True): x, y = inp(‘x’), inp(‘y’) if vr(x) and vr(y): break x, y = int(x), int(y) 50 2011 7 30
  • 51. • while(True): try: x = int(raw_input(‘x(0-2) -> ‘)) y = int(raw_input(‘y(0-2) -> ‘)) except: continue if 0 <= x <= 2 and 0 <= y <= 2: break 51 2011 7 30
  • 52. • inp = lambda n: raw_input(‘%s(0-2) -> ‘%n) vr = lambda n: len(n)==1 and ‘0’ <= n <= ‘2’ while(True): x, y = inp(‘x’), inp(‘y’) if vr(x) and vr(y): break x, y = int(x), int(y) 52 2011 7 30
  • 53. 3 • • • • O or X • • • • 53 2011 7 30
  • 54. O or X 54 2011 7 30
  • 55. • 55 2011 7 30
  • 56. • if field[x + y * 3] != ‘_’: continue 56 2011 7 30
  • 57. • if field[x + y * 3] != ‘_’: continue • if field[x + y * 3] - ‘_’: continue 57 2011 7 30
  • 58. • if field[x + y * 3] != ‘_’: continue • if field[x + y * 3] - ‘_’: continue • 58 2011 7 30
  • 59. 3 • • • • O or X • • • • 59 2011 7 30
  • 60. 60 2011 7 30
  • 61. •8 3 • 61 2011 7 30
  • 62. •8 3 • • OX 62 2011 7 30
  • 63. 0 1 2 3 4 5 6 7 8 63 2011 7 30
  • 64. 0 1 2 n,n+1,n+2 3 4 5 n,n+3,n+6 6 7 8 ???? 64 2011 7 30
  • 65. 0 1 2 n,n+1,n+2 3 4 5 n,n+3,n+6 6 7 8 ???? 65 2011 7 30
  • 66. 0 1 2 n,4,8-n 3 4 5 n,n+1,n+2 6 7 8 n,n+3,n+6 66 2011 7 30
  • 67. 0 1 2 n,4,8-n 3 4 5 n,n+1,n+2 6 7 8 n,n+3,n+6 67 2011 7 30
  • 68. n,4,8-n 0 1 2 3 4 5 n,n+1,n+2 6 7 8 n,n+3,n+6 68 2011 7 30
  • 69. • for i in range(3): if (field[i] != ‘_’ and field[i] == field[i + 1] and field[i] == field[i + 2]): judge = True if (field[4] != ‘_’ and field[4] == field[i] and field[4] == field[8 - i]): judge = True ... 69 2011 7 30
  • 70. • for i in range(3): if (field[i] != ‘_’ and field[i] == field[i + 1] and field[i] == field[i + 2]): judge = True if (field[4] != ‘_’ and field[4] == field[i] and field[4] == field[8 - i]): judge = True ... 70 2011 7 30
  • 71. • mark = ‘ ox’[turn] for i in range(3): if [mark]*3 == [field[i], field[i+1],field[i+2]]: judge = True if [mark]*3 == [field[i],field[4],field[8-i]]: judge = True if [mark]*3 == [field[i], field[i+3],field[i+6]]: judge = True ... 71 2011 7 30
  • 72. • mark = ‘ ox’[turn] jl = lambda line: [mark]*3 == line for i in range(3): if jl([field[i], field[i+1],field[i+2]]): judge = True if jl([field[i],field[4],field[8-i]]): judge = True if jl([field[i], field[i+3],field[i+6]]): judge = True ... 72 2011 7 30
  • 73. • mark = ‘ ox’[turn] jl = lambda line: [mark]*3 == line for i in range(3): if jl([field[i], field[i+1],field[i+2]]): judge = True if jl([field[i],field[4],field[8-i]]): judge = True if jl([field[i], field[i+3],field[i+6]]): judge = True ... 73 2011 7 30
  • 74. • mark = ‘ ox’[turn] jl = lambda line: [mark]*3 == line for i in range(3): if jl(field[i*3:i*3+3]): judge = True if jl(field[i:9-i:4-i]): judge = True if jl(field[i::3]): judge = True 74 2011 7 30
  • 75. • mark = ‘ ox’[turn] jl = lambda line: [mark]*3 == line judge = False for i in range(3): judge = judge or jl(field[i*3:i*3+3]) judge = judge or jl(field[i:9-i:4-i]) judge = judge or jl(field[i::3]) 75 2011 7 30
  • 76. 3 • • • • O or X • • • • 76 2011 7 30
  • 77. 77 2011 7 30
  • 78. • for if 78 2011 7 30
  • 79. • for if • Pythonista 79 2011 7 30
  • 80. • space_flag = False for val in field: if val == ‘_’: space_flag = True if not space_flag: break 80 2011 7 30
  • 81. • space_flag = False for val in field: if val == ‘_’: space_flag = True if not space_flag: break 81 2011 7 30
  • 82. • space_flag = False for val in field: if val == ‘_’: space_flag = True if not space_flag: break • if not ‘_’ in field: break 82 2011 7 30
  • 83. 83 2011 7 30
  • 84. • ‣ turn*=-1 ‣ turn=-turn 84 2011 7 30
  • 85. • ‣ turn*=-1 ‣ turn=-turn ‣ t*=-1 ‣ t=-t 85 2011 7 30
  • 86. 86 2011 7 30
  • 87. • judge • mark 87 2011 7 30
  • 88. • if judge: print ‘%s win’ % mark else: print ‘draw’ 88 2011 7 30
  • 89. • if judge: print ‘%s win’ % mark else: print ‘draw’ • print (‘%s win’ % mark) if judge else ‘draw’ 89 2011 7 30
  • 90. Python 90 2011 7 30
  • 91. Python • 91 2011 7 30
  • 92. Python • • 92 2011 7 30
  • 93. Fin 93 2011 7 30