title: Get the last date of each month in a list of dates in Python
body: <p>I'm using Python 2.7, PyCharm and Anaconda,</p>
  
  <p>I have a <code>list</code> of dates and I'd like to retrieve the last date of each month present in the array.</p>
  
  <p>Are there any functions or libraries that could help me to do this?</p>
  
  <p>I read the dates from a CSV file and stored them as <code>datetime</code>.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>Dates=[]
  Dates1=[]
  for date in dates:
      temp=xlrd.xldate_as_tuple(int(date),0)
      Dates1.append(datetime.datetime(temp[0],temp[1],temp[2]))
  
  for date in Dates1:
      if not (date&lt;startDate or date&gt;endDate):
          Dates.append(date)
  </code></pre>
  
  <p>To make it clear, suppose I have:</p>
  
  <pre><code>Dates = [2015-01-20, 2015-01-15, 2015-01-17, 2015-02-21, 2015-02-06] 
  </code></pre>
  
  <p>(Consider it being in <code>datetime</code> format.)</p>
  
  <p>The list I'd like to retrieve is:</p>
  
  <pre><code>[2015-01-20, 2015-02-21]
  </code></pre>
  
  <p>So far I've googled around, especially in Stack Overflow, but I could only find answers to how I could get the last date of each month, but not from a user-specified list.</p>