code: def get_markdown_levels(lines, levels=set((0, 1, 2, 3, 4, 5, 6))):
      r
      if isinstance(levels, (int, float, basestring, str, bytes)):
          levels = [float(levels)]
      levels = set([int(i) for i in levels])
      if isinstance(lines, basestring):
          lines = lines.splitlines()
      level_lines = []
      for line in lines:
          level_line = None
          if 0 in levels:
              level_line = (0, line)
          lstripped = line.lstrip()
          for i in range(6, 1, -1):
              if lstripped.startswith('#' * i):
                  level_line = (i, lstripped[i:].lstrip())
                  break
          if level_line and level_line[0] in levels:
              level_lines.append(level_line)
      return level_lines
docs: r""" Return a list of 2-tuples with a level integer for the heading levels
  
      >>> get_markdown_levels('paragraph \n##bad\n# hello\n  ### world\n')
      [(0, 'paragraph '), (2, 'bad'), (0, '# hello'), (3, 'world')]
      >>> get_markdown_levels('- bullet \n##bad\n# hello\n  ### world\n')
      [(0, '- bullet '), (2, 'bad'), (0, '# hello'), (3, 'world')]
      >>> get_markdown_levels('- bullet \n##bad\n# hello\n  ### world\n', 2)
      [(2, 'bad')]
      >>> get_markdown_levels('- bullet \n##bad\n# hello\n  ### world\n', 1)
      []