title: What is the best method to fill in missing months in a list using datetime?
body: <p>The main purpose of the program I am trying to make is to be able to fill in (insert) a list of objects with have a price and a datetime, if there is a missing month, and if there is, insert a duplicate object but with the correct month, and the last day of that specific month with the same price (no change)</p>
  <p>Here is an example.
  Let's say that the list <code>dateprices</code> was filled with objects dynamically somewhere else in the program. Each item (<code>datePriceObj</code>) has the variables: <code>date</code> which is the datetime object, and <code>price</code> which is the price for that date (let's say it was the value of a product on Amazon or something, doesn't matter.)</p>
  <p>What I'm trying to achieve is shown below:</p>
  <p>The class to create the objects below</p>
  <pre><code>class DatePriceCreator():
      def __init__(self, datetimeObj, priceFloat):
          self.date = datetimeObj
          self.price = priceFloat
  </code></pre>
  <p>What I have currently, that needs changing so that months are filled in correctly:</p>
  <pre><code>datePrices = [datePriceObj, datePriceObj, datePriceObj, datePriceObj, datePriceObj]
  
  
  # datePrices[0].date is equal to 25th October 2019 (this is a datetime object)
  # datePrices[1].date is equal to 23rd November 2019 (this is a datetime object)
  # datePrices[2].date is equal to 26th February 2020 (this is a datetime object)
  # datePrices[3].date is is equal to 26th March 2020 (this is a datetime object)
  # datePrices[4].date is equal to 15th May 2020 (this is a datetime object)
  
  # datePrices[0].price is equal to 1000.0 (this is a float)
  # datePrices[1].price is equal to 1056.0 (this is a float)
  # datePrices[2].price is equal to 1700.0 (this is a float)
  # datePrices[3].price is equal to 1750.0 (this is a float)
  # datePrices[4].price is equal to 2007.0 (this is a float)
  </code></pre>
  <p>Expected Output:</p>
  <pre><code># Expected Output:
  datePrices = [datePriceObj, datePriceObj, datePriceObj, datePriceObj. datePriceObj, datePriceObj, datePriceObj, datePriceObj]
  
  # datePrices[0].date is equal to 25th October 2019 (this is a datetime object)
  # datePrices[1].date is equal to 23rd November 2019 (this is a datetime object)
  # datePrices[2].date is equal to 31st December 2019 (this is a datetime object)
  # datePrices[3].date is equal to 31st January 2020 (this is a datetime object)
  # datePrices[4].date is equal to 26th February 2020 (this is a datetime object)
  # datePrices[5].date is is equal to 26th March 2020 (this is a datetime object)
  # datePrices[6].date is is equal to 30th April 2020 (this is a datetime object)
  # datePrices[7].date is equal to 15th May 2020 (this is a datetime object)
  
  # datePrices[0].price is equal to 1000.0 (this is a float)
  # datePrices[1].price is equal to 1056.0 (this is a float)
  # datePrices[2].price is equal to 1056.0 (this is a float)
  # datePrices[3].price is equal to 1056.0 (this is a float)
  # datePrices[4].price is equal to 1700.0 (this is a float)
  # datePrices[5].price is equal to 1750.0 (this is a float)
  # datePrices[6].price is equal to 1750.0 (this is a float)
  # datePrices[7].price is equal to 2007.0 (this is a float)
  </code></pre>
  <p>As you can see for the Expected Output, new objects have been filled in the list, and those new objects contain the date with the filled-in month, and with the last day of that month as well as the price which is unchanged from the previous.</p>
  <p>The issue I'm facing is how to do this, so no matter what the year is, it will always have the next month. This is shown on the Expected Output for <code>datePrices[2]</code> and <code>datePrices[3]</code>, where it recognises that the year has changed. I'm not sure how to go about doing this. Possibly using a while loop of some sort to continue making objects and inserting in the list until <code>datePrices[x+1].date.month - 1</code> is equal to <code>datePrices[x].date.month</code>, but this would only work if <code>datePrices[x].date.month is &lt;= 11</code>. If it was <code>12</code>, the next month would have to be <code>13</code>, but there is no 13th month.</p>
  <p>I am a beginner in this, and was wondering what the most efficient solution to this would be without using too many conditionals unless absolutely neccessary.</p>