看板 Python 關於我們 聯絡資訊
※ 引述《KagiJhou (Kagi)》之銘言: : 試著用3.12的方式寫寫看 : st=input("string:") : pos=input("possition:") : z = list(zip(st,pos)) : # 指定z是list : z.sort(key= (lambda key:key[1]) ) : print ("".join([s[0] for s in z])) 如果不想用 zip 的話 st=input("string:") pos=input("possition:") # sort_key: 到st抓c的index 再拿index去pos取位置 sort_key = lambda c: pos[st.index(c)] sort_st = sorted(st, key = sort_key) # 排序 new_st = ''.join(sort_st) print new_st (in Python 2.6.5) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.195.10.146
apua:這方法漂亮多了@@ 04/16 11:41