1

I have two arrays:

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)]

I want to exchange last_months array numbers to strings from months. How can i do that ?

Thank for help in advance.

user2390182
  • 72,016
  • 6
  • 67
  • 89
Robson
  • 1,207
  • 3
  • 21
  • 43

1 Answers1

1

You can wrap the indexer part of your last_months inside an array lookup.

[months[(current_month - i - 1) % len(months) + 1] for i in range(7)]
Sayse
  • 42,633
  • 14
  • 77
  • 146