我的代碼——
match key:
case list(map(ord, map( str, range(1,10) )):
#...
這個映射函式使這種格式——
[ord('1'), ord('2'), ord('3'), ...]從 1 到 9
但想要像 [ord('1') | ord('2') | ...]
我怎樣才能做到這一點?
uj5u.com熱心網友回復:
嘗試:
match key:
case key if key in map(ord, map( str, range(1,10))):
#...
注意:不要雙重map使用理解:
>>> [ord(str(i)) for i in range(1, 10)]
[49, 50, 51, 52, 53, 54, 55, 56, 57]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/340160.html
標籤:Python 列表 映射 python-3.10
上一篇:將所有值從串列添加到串列串列
下一篇:Python,索引超出范圍,串列
