title: Faster drawing in python pygame
body: <p>I made a program using Python, with pygame, that loads pictures of materials and then creates blocks and each block is assigned with random material.
  Block is a class and in the drawing process, it iterates through the array with stored blocks, but that is very slow. Isn't there a faster method than storing them in array and iterating through?</p>
  
  <pre><code>class block:
      def __init__(self, texture, x, y):
             self.texture = texture
             self.x = x
             self.y = y
  
  
  material = pygame.image
  material.grass = pygame.image.load("textures/grass.png")
  material.water = pygame.image.load("textures/water.png")
  material.sand = pygame.image.load("textures/sand.png")
  
  materials = [material.grass, material.water, material.sand]
  
  
  
  white = (255,255,255);(width, height) = (2048, 1008);black = (0, 0, 0);screen = pygame.display.set_mode((width, height))
  
  b_unit = 16
  
  b = []
  
  count = 0
  cx = 0
  cy = 0
  while count &lt; (width * height) / (b_unit * b_unit):
      b.append(block(random.choice(materials), b_unit * cx, b_unit * cy))
      cx += 1
      count += 1
      if cx == width / b_unit:
          cx = 0
          cy += 1
  
  while True:
      for block in b:
          screen.blit(block.texture, (block.x + viewx, block.y + viewy))
      pygame.display.flip()
  </code></pre>