def render(board: list, moves: list): """ mutate the board, then render it """ for p in moves: theplay = p[1] l = len(theplay) comp = re.compile('([KQBNRP])?([a-h][1-8])(x?)([a-h][1-8])([\+#]?)') mat = comp.match(theplay) grps = mat.groups(0) frm = grps[1] frm_col = colval(frm[0]) frm_row = rowval(frm[1]) to = grps[3] to_col = colval(to[0]) to_row = rowval(to[1]) frm_piece = board[frm_row][frm_col] to_piece = board[to_row][to_col] board[to_row][to_col] = board[frm_row][frm_col] board[frm_row][frm_col] = '' for row in board[::-1]: for cell in row: if len(cell) > 0: if islower(cell): print(f" {white}{black_back}{cell}{reset_color}", end='') elif isupper(cell): print(f" {red}{black_back}{cell}{reset_color}", end='') else: print(f" {black_back}-{reset_color}", end='') print('')
def reverse_upper_low(the_str): new_str='' for d in the_str: if isalpha(d): if isupper(d): new_str+=d.lower() else: new_str+=d.upper() else: new_str+=d print new_str
def easy(): states, R = [("start", ["start"])], 0 while states: states_, states = states, [] for pos, hist in states_: for path in t[pos]: if path == "end": R += 1 continue if path in hist and not isupper(path[0]): continue states.append((path, hist + [path])) print(R)
def store_register(word): """ For a given word returns a list of 0 and 1 where 1 represents capital letter, and 0 is lowercase :param word: word to process into 0 and 1 :return: list of 0 and 1 with the length of the word """ index = [] char_array = list(word) for each_char in char_array: if isupper(each_char): index.append(True) else: index.append(False) return index
def hard(): states, R = [("start", ["start"], 0)], 0 while states: states_, states = states, [] for pos, h, F in states_: for p in t[pos]: if p == "end": R += 1 continue if p in h and not isupper(p[0]): if not F and p != "start" and p != "end" and h.count( p) == 1: states.append((p, h + [p], 1)) continue states.append((p, h + [p], F)) print(R)
def _加教育部例句(apps, schema_editor): 例句表 = apps.get_model("例句", "例句表") with open(join(dirname(abspath(__file__)), '..', '語料', '例句.csv')) as 檔: 讀檔 = DictReader(檔) for row in 讀檔: 漢字 = row['例句'].strip() 音標 = row['例句標音'].strip() 華語 = row['華語翻譯'].strip() if 華語 == '': 華語 = 漢字 if isupper(音標[0]) and 音標[-1] in 標點符號: 句物件 = ( 拆文分析器 .對齊句物件(漢字, 文章粗胚.建立物件語句前處理減號(臺灣閩南語羅馬字拼音, 音標)) .轉音(臺灣閩南語羅馬字拼音) ) 例句表.objects.create(漢字=漢字, 臺羅=音標, 華語=華語, 分詞=句物件.看分詞())
def 走(): with transaction.atomic(): 版權表.objects.get_or_create(版權='會使公開') 資料庫 = 佳怡表匯入資料庫() 公家內容 = { '收錄者': 來源表.objects.get_or_create(名='鄉民')[0], '來源': 資料庫.來源內容(), '版權': '會使公開', '語言腔口': settings.MOTHER_TONGUE, '著作所在地': '臺灣', '著作年': '2014', } a = 0 for 漢字, 音標, 華語 in 資料庫.資料(): a += 1 print(a) if len(音標) > 0 and isupper(音標[0]): 種類 = '語句' else: 種類 = '字詞' 閩南語內容 = { '文本資料': 漢字, '種類': 種類, '屬性': {'音標': 音標}, } 閩南語內容.update(公家內容) if len(華語) > 0: for 華 in 華語: 外語內容 = { '種類': 種類, '外語語言': '華語', '外語資料': 華 } 外語內容.update(公家內容) try: 外語平臺項目 = 平臺項目表.加外語資料(外語內容) 外語平臺項目編號 = 外語平臺項目.編號() except ValidationError as 錯誤: 外語平臺項目編號 = 錯誤.平臺項目編號 文本平臺項目 = 平臺項目表.外語翻母語(外語平臺項目編號, 閩南語內容) 文本平臺項目.設為推薦用字() else: pass
def 走(): 來源表.objects.get_or_create(名='鄉民') 版權表.objects.get_or_create(版權='會使公開') 種類表.objects.get_or_create(種類=字詞) 種類表.objects.get_or_create(種類=語句) 資料庫=佳怡表匯入資料庫() 公家內容 = { '收錄者':1, '來源':資料庫.來源內容(), '版權':'會使公開', # '種類':'字詞', '語言腔口':'閩南語', '著作所在地':'臺灣', '著作年':'2014', # '屬性':self.詞屬性, } for 漢字,音標,華語 in 資料庫.資料(): if len(音標)>0 and isupper(音標[0]): 種類='語句' else: 種類='字詞' 閩南語內容={ '文本資料':漢字, '種類':種類, '屬性':{'音標':音標}, } 閩南語內容.update(公家內容) if len(華語)>0: for 華 in 華語: 外語內容={ '種類':種類, '外語語言':'華語', '外語資料':華} 外語內容.update(公家內容) try: 外語平臺項目=平臺項目表.找外語資料(外語內容) except: 外語平臺項目=平臺項目表.加外語資料(外語內容) 平臺項目表.外語翻母語(外語平臺項目.編號(), 閩南語內容) # 外語=外語表.加資料(外語內容) # 外語.翻母語(閩南語內容) else: pass
def 走(): 來源表.objects.get_or_create(名='鄉民') 版權表.objects.get_or_create(版權='會使公開') 種類表.objects.get_or_create(種類=字詞) 種類表.objects.get_or_create(種類=語句) 資料庫 = 佳怡表匯入資料庫() 公家內容 = { '收錄者': 1, '來源': 資料庫.來源內容(), '版權': '會使公開', # '種類':'字詞', '語言腔口': '臺語', '著作所在地': '臺灣', '著作年': '2014', # '屬性':self.詞屬性, } for 漢字, 音標, 華語 in 資料庫.資料(): if len(音標) > 0 and isupper(音標[0]): 種類 = '語句' else: 種類 = '字詞' 閩南語內容 = { '文本資料': 漢字, '種類': 種類, '屬性': { '音標': 音標 }, } 閩南語內容.update(公家內容) if len(華語) > 0: for 華 in 華語: 外語內容 = {'種類': 種類, '外語語言': '華語', '外語資料': 華} 外語內容.update(公家內容) try: 外語平臺項目 = 平臺項目表.找外語資料(外語內容) except: 外語平臺項目 = 平臺項目表.加外語資料(外語內容) 平臺項目表.外語翻母語(外語平臺項目.編號(), 閩南語內容) # 外語=外語表.加資料(外語內容) # 外語.翻母語(閩南語內容) else: pass
def 走(): with transaction.atomic(): 版權表.objects.get_or_create(版權='會使公開') 資料庫 = 佳怡表匯入資料庫() 公家內容 = { '收錄者': 來源表.objects.get_or_create(名='鄉民')[0], '來源': 資料庫.來源內容(), '版權': '會使公開', '語言腔口': settings.MOTHER_TONGUE, '著作所在地': '臺灣', '著作年': '2014', } a = 0 for 漢字, 音標, 華語 in 資料庫.資料(): a += 1 print(a) if len(音標) > 0 and isupper(音標[0]): 種類 = '語句' else: 種類 = '字詞' 閩南語內容 = { '文本資料': 漢字, '種類': 種類, '屬性': { '音標': 音標 }, } 閩南語內容.update(公家內容) if len(華語) > 0: for 華 in 華語: 外語內容 = {'種類': 種類, '外語語言': '華語', '外語資料': 華} 外語內容.update(公家內容) try: 外語平臺項目 = 平臺項目表.加外語資料(外語內容) 外語平臺項目編號 = 外語平臺項目.編號() except ValidationError as 錯誤: 外語平臺項目編號 = 錯誤.平臺項目編號 文本平臺項目 = 平臺項目表.外語翻母語(外語平臺項目編號, 閩南語內容) 文本平臺項目.設為推薦用字() else: pass
def toColumnLine(c, l): if ascii.isalpha(c) == False: print("invalid column") return -1, -1 if ascii.isupper(c): cColumn = c.lower() else: cColumn = c column = ord(cColumn) - ord('a') if column < 0 or column > 7: print("invalid column") return -1, -1 if ascii.isdigit(l) == False: print("invalid line") return -1, -1 line = int(l) - 1 line = 7 - line if line < 0 or line > 7: print("invalid line") return -1, -1 return column, line
def toColumnLine(c, l): if ascii.isalpha(c) == False: print "invalid column" return -1,-1 if ascii.isupper(c): cColumn = string.lower(c) else: cColumn = c column = ord(cColumn) - ord('a') if column < 0 or column > 7 : print "invalid column" return -1,-1 if ascii.isdigit(l) == False: print "invalid line" return -1,-1 line = int(l) - 1 line = 7 - line if line < 0 or line > 7: print "invalid line" return -1,-1 return column, line
def render(board: list, moves: list): """ mutate the board, then render it """ for p in moves: theplay = p[1] l = len(theplay) comp = re.compile('([KQBNRP])?([a-h][1-8])(x?)([a-h][1-8])([\+#]?)') mat = comp.match(theplay) grps = mat.groups(0); frm = grps[1] frm_col = colval(frm[0]) frm_row = rowval(frm[1]) to = grps[3] to_col = colval(to[0]) to_row = rowval(to[1]) frm_piece = board[frm_row][frm_col] to_piece = board[to_row][to_col] board[to_row][to_col] = board[frm_row][frm_col] board[frm_row][frm_col] = '' therow = 8 for i, row in enumerate(board[::-1]): print(f'<tr><td class="cell-legend">{therow-i}</td>') for cell in row: if len(cell) > 0: if islower(cell): print(f" <td class='cell white-black'><img src='{imgsrc(cell)}' alt='{cell}'/></td>", end='') elif isupper(cell): print(f" <td class='cell red-black'><img src='{imgsrc(cell)}' alt='{cell}'/></td>", end='') else: print(f" <td class='cell silver-black'>-</td>", end='') print('</tr><tr>') print("<td class='cell-legend'> </td>"); for letter in range(97, 97+8): print(f"<td class='cell-legend'>{chr(letter).upper()}</td>") print('</tr>')
def find_char(): with open("3.txt") as f: lines = f.readlines() for line in lines: line = line.strip() result = '' upper_count = 0 for char in line: if isupper(char): upper_count += 1 elif upper_count == 3: if result == '': result = char upper_count = 0 else: print result result = '' else: result = '' upper_count = 0
def isPortalChar(char): return na.isupper(char)