我想知道特定日期(在此示例中为今天的日期)是否是世界上某个地方的假期。如果是 - 我想在每个元组中创建带有元组的列表 - (假期名称,世界上的哪个地方)。如果它不是任何地方的假期 - 空列表。我试图导入假期,但我需要像这个例子一样在每个国家运行:有人有更高效的东西吗?
from datetime import date
import holidays
listOfHolidays = []
for ptr in holidays.ISR(years=date.today().year).items():
if date.today() == ptr[0]:
listOfHolidays.append(tuple((ptr[1], "ISRAEL")))
for ptr in holidays.US(years=date.today().year).items():
if date.today() == ptr[0]:
listOfHolidays.append((tuple(ptr[1], "US")))
for ptr in holidays.UK(years=date.today().year).items():
if date.today() == ptr[0]:
listOfHolidays.append((tuple(ptr[1], "UK")))
for ptr in holidays.CHN(years=date.today().year).items():
if date.today() == ptr[0]:
listOfHolidays.append((tuple(ptr[1], "CHN")))
print(listOfHolidays)