作者suhang (suhang)
看板Python
标题[问题] int convert to another int val
时间Sat Jun 30 15:41:25 2018
python built-in weeday
Mon = 0
Tue = 1
.
.
Sun = 6
我抓回来的资料
Mon = 1
Tue = 2
.
.
Sun = 0
需要在两个weekday 里面做单向对应转换
丑方法 1.
抓回来的资料
weekday -= 1
if weekday == -1:
weekday = 0
方法2.
我可以简单做一个 dict mapping一下就好
方法3. ?
有什麽其他好方法可以让这个转换看起来高级而且可读性高吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 172.89.32.145
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1530344487.A.A0D.html
※ 编辑: suhang (172.89.32.145), 06/30/2018 15:41:52
1F:推 cutekid: 6 - (7 - day) % 7 = 答案 06/30 16:10
2F:推 ckc1ark: (day+6)%7不好吗 06/30 16:42
3F:推 cutekid: 推 ck 大 06/30 21:19
4F:推 rexyeah: isoweekday() 不过sunday = 7 不符合你要的...Orz 07/03 12:54
5F:推 flarehunter: 什麽方法都行,只要用个函式包起来可读性就高 07/04 19:17