1
def convert_number_into_months_range(number):
    zodiac_months = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]
    first_month = zodiac_months[number]
    if number == len(zodiac_months) - 1:
        second_month = zodiac_months[0]
    else:
        second_month = zodiac_months[number + 1]
    return first_month, second_month

This is my example. It works, but looks unpythonic. On Input we have an index of the list. On return we have tuple of (index, index+1) elements of the list. If the index is pointing on the last element then we should get (last, first) elements. Is there are way to do it in more pythonicaly?

ggguser
  • 1,872
  • 12
  • 9

1 Answers1

0

You can try this:

def convert_number_into_months_range(number):
    zodiac_months = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]
    return zodiac_months[number], zodiac_months[(number + 1) % len(zodiac_months)])
Taohidul Islam
  • 5,246
  • 3
  • 26
  • 39