Re: [問題]沒頭緒的一個問題...

看板Python作者 (ccc)時間15年前 (2010/04/16 00:18), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串5/5 (看更多)
※ 引述《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

04/16 11:41, , 1F
這方法漂亮多了@@
04/16 11:41, 1F
文章代碼(AID): #1BnpnaUW (Python)
文章代碼(AID): #1BnpnaUW (Python)