看板 Python 關於我們 聯絡資訊
大家好 我最近在學習python的建立函數 想請問該如何解決下列問題 我現在有以下的資訊 zipcode = {"台北市": {"中正區": 100, "大同區": 103, "中山區": 104},"新北市": {"萬里區": 207, "金山區": 208, "板橋區": 220, "汐止區": 221}} 現在要求一個函式 當輸入台北市的時候 就會印出台北市內所有區的郵遞區號 我寫出來是這樣 def fun (city): n=input('type city:') for n in city : print value for value in zipcode.get(city).values() city=("台北市","新北市") 不知道要怎麼改 還請各位高手幫忙!!謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.245.65.183 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1446087278.A.D3D.html
bigpigbigpig: 一行for d, code in zipcode[city].items()就搞定了 10/29 11:24
banyhong: [zipcode['台北市'][k] for k in zipcode['台北市']] 11/06 00:57