title: IndexError: list index out of range pygame
body: <p>It says that the list index is out of range, and I don't know why. Does anyone know how to fix the problem?</p>
  <p>Code for thing I'm importing</p>
  <pre class="lang-py prettyprint-override"><code>from os import walk
  import pygame
  
  def import_folder(path):
      surface_list = []
  
      for _, __, img_files in walk(path):
          for image in img_files:
              full_path = path + '/' + image
              image_surf = pygame.image.load(full_path).convert_alpha()
              surface_list.append(image_surf)
  
      return surface_list
  </code></pre>
  <p>Code for thing I'm using it in:</p>
  <pre class="lang-py prettyprint-override"><code>import pygame
  from support import import_folder
  
  class Player(pygame.sprite.Sprite):
      def __init__(self, pos):
          super().__init__()
          self.import_character()
          self.frame_index = 0
          self.animation_speed = 0.15
          self.image = self.animations['run'][self.frame_index]
          
          # Player Movement
  
          self.direction = pygame.math.Vector2(0, 0)
          self.speed = 8
          self.gravity = 0.8
          self.jump_speed = -16
  
      def import_character(self):
          character_path = '../graphics/character/'
          self.animations = {'idle':['idle'], 'run':[], 'jump':[], 'fall':[]}
  
          for animation in self.animations.keys():
              full_path = character_path + animation
              self.animations[animation] = import_folder(full_path)
  </code></pre>
  <p>Full Error Code (starting from Traceback):</p>
  <pre><code>Traceback (most recent call last):
  File &quot;C:\Users\Daniel\Desktop\PlatformerGame.py&quot;, line 
  13, in &lt;module&gt;
  level = level(level_map, window)
  File &quot;C:\Users\Daniel\Desktop\level.py&quot;, line 11, in 
  __init__
  self.setup_level(level_data)
  File &quot;C:\Users\Daniel\Desktop\level.py&quot;, line 27, in 
  setup_level
  player_sprite = Player((x, y))
  File &quot;C:\Users\Daniel\Desktop\player.py&quot;, line 10, in 
  __init__
  self.image = self.animations['run'][self.frame_index]
  IndexError: list index out of range
  </code></pre>