Calculate possible date combination without year

Question:

I am trying to calculate possible date combination without year,

Input :

date_first = 1/1/2016,
date second = 31/12/2016

Output : in output I need a list of all possible combination of day and month see this example.

01/01 to 12/31
01/01 to 12/30
01/01 to 12/29
01/01 to 12/28, etc.
...............
01/02 to 12/31
01/02 to 12/30
01/02 to 12/29
01/02 to 12/28, etc.
..............
12/31 to 12/31

I calculated year range using

rngs = date_range('1/1/2016', periods=365, freq='M')

date_range_list = [rng.date() for rng in rngs]

but for calculating possible date combination without year , I need to run two loops that is taking to long time. so if any one know please help me to resolved this issue. Thanks in advance.

Let me clear more about problem I am getting :

I want a list of all possible combination of day and month, like, if Input date range is 1/1/2016 to 4/1/2016, combination output will be :

[['1/1',4/1], ['1/1','3/1'],['1/1','2/1']['1/1','1/1'],['2/1','4/1'],['2/1','3/1'],['2/1','2/1‌​'],....]

Answers:

Use itertools.combinations:

from itertools import combinations
import pandas as pd
rngs = pd.date_range('1/1/2016', periods=365, freq='M')
date_range_list = [rng.date() for rng in rngs]
result = combinations(date_range_list, 2)
Answered By: Muhammad Tahir
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.