title: Print heading and corresponding paragraph in beautiful soup
body: <p>Here is my code</p>
  
  <pre><code>soup = BeautifulSoup(open('MUFC.html'))
  
  a_tag = soup.find_all()
  f=open('out.txt','w')
  i=0
  while(i&lt;len(a_tag)):
      if(a_tag[i].find('&lt;h1&gt;') or a_tag[i].find('&lt;h2&gt;') or a_tag[i].find('&lt;h3&gt;')):
          f.write(a_tag[i].get_text().encode('utf-8'))
          f.write('\n')
          i=i+1
          f.write(a_tag[i].get_text().encode('utf-8'))
          f.write('\n')
      elif(a_tag[i].find('&lt;p&gt;')):
          f.write(a_tag[i].get_text().encode('utf-8'))
          f.write('\n')
          i=i+1
      i=i+1
  </code></pre>
  
  <p>What I want to do is take heading and corresponding paragraph(s), but this takes a lot of time.</p>
  
  <p>My sample Input is </p>
  
  <pre><code>&lt;h1&gt;Manchester United F.C.&lt;/h1&gt;
  &lt;p&gt;
  Manchester United Football Club is an English professional football club, based in Old Trafford, Greater Manchester that plays in the Premier League. Founded as Newton Heath LYR Football Club in 1878, the club changed its name to Manchester United in 1902 and moved to Old Trafford in 1910 and is one of the most successful clubs in English football.
  &lt;/p&gt;
  
  &lt;p&gt;
  Manchester United have won the most League titles (20) of any English club,[3] a joint record 11 FA Cups, four League Cups, and a record twenty FA Community Shields. The club has also won three European Cups, one UEFA Cup Winners' Cup, one UEFA Super Cup, one Intercontinental Cup, and one FIFA Club World Cup. In 1998–99, the club won a continental treble of the Premier League, the FA Cup and the UEFA Champions League.
  &lt;/p&gt;
  
  &lt;h3&gt;Early years (1878–1945)&lt;/h3&gt;
  &lt;p&gt;
  Manchester United was formed in 1878 as Newton Heath LYR Football Club by the Carriage and Wagon department of the Lancashire and Yorkshire Railway (LYR) depot at Newton Heath.[15] The team initially played games against other departments and rail companies, but on 20 November 1880, they competed in their first recorded match; wearing the colours of the railway company – green and gold – they were defeated 6–0 by Bolton Wanderers' reserve team.[16] By 1888, the club had become a founding member of The Combination, a regional football league. Following the league's dissolution after only one season, Newton Heath joined the newly formed Football Alliance, which ran for three seasons before being merged with the Football League. This resulted in the club starting the 1892–93 season in the First Division, by which time it had become independent of the rail company and dropped the "LYR" from its name.[15] After two seasons, the club was relegated to the Second Division.[15]
  &lt;/p&gt;
  </code></pre>
  
  <p>What I want as output is something like </p>
  
  <pre><code> Manchester United F.C.
  
      Manchester United Football Club is an English professional football club, based in Old Trafford, Greater Manchester that plays in the Premier League. Founded as Newton Heath LYR Football Club in 1878, the club changed its name to Manchester United in 1902 and moved to Old Trafford in 1910 and is one of the most successful clubs in English football.
  
  
      Manchester United have won the most League titles (20) of any English club,[3] a joint record 11 FA Cups, four League Cups, and a record twenty FA Community Shields. The club has also won three European Cups, one UEFA Cup Winners' Cup, one UEFA Super Cup, one Intercontinental Cup, and one FIFA Club World Cup. In 1998–99, the club won a continental treble of the Premier League, the FA Cup and the UEFA Champions League.
  
  
      Early years (1878–1945)
  
      Manchester United was formed in 1878 as Newton Heath LYR Football Club by the Carriage and Wagon department of the Lancashire and Yorkshire Railway (LYR) depot at Newton Heath.[15] The team initially played games against other departments and rail companies, but on 20 November 1880, they competed in their first recorded match; wearing the colours of the railway company – green and gold – they were defeated 6–0 by Bolton Wanderers' reserve team.[16] By 1888, the club had become a founding member of The Combination, a regional football league. Following the league's dissolution after only one season, Newton Heath joined the newly formed Football Alliance, which ran for three seasons before being merged with the Football League. This resulted in the club starting the 1892–93 season in the First Division, by which time it had become independent of the rail company and dropped the "LYR" from its name.[15] After two seasons, the club was relegated to the Second Division.[15]
  </code></pre>
  
  <p>Can we improvise this?</p>