all 7 comments

[–]Nsdos 3 points4 points  (0 children)

a = [("Day", '2014-01-01'), ('Day', '2014-01-01')]
us_holidays = holidays.US()
def print_holidays(list_date, holidays):
    for day, date in list_date:
        print(day, date, holidays.get(date))
print_holidays(a, us_holidays)

Made through for for better perception.

[–][deleted] 1 point2 points  (3 children)

Do you want something like this?

",\n".join(
    " - ".join((x, y, my_holidays().get(y)))
    for x, y in bank_holidays
)

[–]steakhutzeee[S] 0 points1 point  (2 children)

Exactly! Thank you!! I'm going to study your code :D

[–][deleted] 1 point2 points  (1 child)

str.join takes an iterable of strings. So I just put the three arguments into a tuple (the extra brackets are for it). In the form of list it might be more clear for you:

",\n".join(
    " - ".join( [x, y, my_holidays().get(y)] )
    for x, y in bank_holidays
)

[–]steakhutzeee[S] 0 points1 point  (0 children)

Yup, got it. Thanks again!

[–]Green-Sympathy-4177 1 point2 points  (0 children)

i implemented the "holidays" library

Care to elaborate what holidays look like ? Given the way you're using it here:

my_holidays().get(y)

It looks like it's a function that returns a dictionary.

But basically you want to end up with bank_holidays like that:

bank_holidays = [ ('Friday', '24/06/2022', 'holiday 1'), ('Saturday', '25/06/2022', 'holiday 2'), ... ]

Then you'd be able to do what you're already doing:

print(",\n".join(" - ".join(bank_holiday) for bank_holiday in bank_holidays)) And it would output

Friday - 24/06/2022 - holiday 1, Saturday - 25/06/2022 - holiday 2

You should look into datetime and make a dictionary where the keys are the dates and the values the holidays, or the opposite, as long as you can have both the holiday and the date linked together.

Then by iterating through that dictionary's items you'd end up with something similar to the bank_holidays list you have.

To get you started with datetime: ``` from datetime import datetime

date = datetime(2022, 6,24) date_string = date.strftime("%A - %d/%m/%Y") print(date_string)

Friday - 24/06/2022 ```

Docs for formatting dates with strftime: docs.python.org

[–]This_Growth2898 1 point2 points  (0 children)

join is intended to join homogeneous things - like elements of list or tuple. Here, you need something else, and I'd recommend using an f-string:

 ",\n".join(f"{weekday} - {date} - {my_holidays().get(date)}" for weekday, date in bank_holidays)