我有两个数组:
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
current_month = datetime.date.today().month
last_months = [(current_month - i - 1) % len(months) + 1 for i in range(7)]
我想将last_months
数组号码交换为months
的字符串。
我怎么能这样做?
提前感谢您的帮助。
答案 0 :(得分:1)
您可以将last_months
的索引器部分包装在数组查找中。
[months[(current_month - i - 1) % len(months) + 1] for i in range(7)]