title: How to access a list initialized in a class
body: <p>I am new to programming and have decided to create a card game in python to learn more. I believe I have complicated my code more than necessary and coded myself into a corner, so I could use some guidance. I recognize my code is a bit of a logistical nightmare, so I will take any pointers you can give.</p>
  <p>I am creating a high-low game that has a grid of 9 stacks of cards to choose from. The player chooses any of the cards and guesses if the next card pulled from the deck will be higher or lower than the card they chose. Regardless of whether or not they are right, the new card is added to the top of whichever stack was chosen. The grid itself is a list called table that contains the 9 stacks of cards. Once the deck has run out, I want to remove the last stack in the grid and append it to my deck, thus giving more cards to play with.</p>
  <p>My Deck class creates my deck and holds logic for shuffling, drawing, counting, etc</p>
  <pre><code>class Deck:
      def __init__(self):
          self.cards = []
  
  
      def build(self):
          for s in suits:
              for v in range(1, 14):
                  self.cards.append(Card(s,v))
  
      def show(self):
          print(self.cards)
  
      def shuffle(self):
          for i in range(len(self.cards) - 1, 0, -1):
              r = random.randint(0, i)
              self.cards[i], self.cards[r] = self.cards[r], self.cards[i]
  
      def drawCard(self):
          return self.cards.pop()
  
      def countDeck(self):
          return len(self.cards)
  
      def getTopCard(self):
          print(self.cards[0])
  </code></pre>
  <p>My Stack class includes logic for adding, counting, removing stacks.</p>
  <pre><code>class Stack:
      def __init__(self):
          self.cards = []
  
      def __repr__(self):
          return &quot;{}&quot;.format(self.cards)
  
      def add(self, card):
          self.cards.insert(0, card)
  
      def showStack(self):
          for card in self.cards:
              card.show()
      
      def countStack(self):
          return len(self.cards)
  
      def removeStack(self, card):
          self.cards.remove(card)
          deck.cards.append(card)
  </code></pre>
  <p>My Setup class then creates the table by building the grid of 9 stacks</p>
  <pre><code>class Setup:
      def __init__(self, deck):
          self.table = []
  
      def buildStacks(self, deck):
          for s in range(9):
              stack = Stack()
              c = deck.drawCard()
              stack.add(c)
              self.table.append(stack)
          print(self.table)
  </code></pre>
  <p>Within my Game class I have the logic for comparing the card in the chosen stack with the new card pulled from the deck. Here is where I believe I should be checking to see if the deck has run out of cards, and calling my Stack.removeStack() method. <em>For the purpose of testing, I have set the conditional to remove the last stack if the deck gets to len 40.</em></p>
  <pre><code>    def compareCards(self, currCard, stackIndex):
          newCard = self.deck.drawCard()
          newCardVal = newCard.value
          choice = input(&quot;Higher or Lower?&quot;).capitalize()
          # get index of stack to add new card
          stackCount = self.setup.table[stackIndex].countStack()
          if choice == &quot;Higher&quot; and newCardVal &lt; currCard:
              print(&quot;You failed!&quot;, newCardVal, &quot; is lower than &quot;, currCard)
             
          elif choice == &quot;Lower&quot; and newCardVal &gt; currCard:
              print(&quot;You failed!&quot;, newCardVal, &quot; is higher than &quot;, currCard)
              
          elif newCardVal == currCard:
              print(&quot;You failed!&quot;, newCardVal, &quot; is the same as &quot;, currCard)
              
          else:
              print(&quot;You chose to go &quot;, choice, &quot; on &quot;, currCard, &quot;.&quot;)
              print(&quot;The new card you pulled was &quot;, newCardVal)
              print(&quot;Nice!&quot;)
              self.round += 1
              print(&quot;Round: &quot;, self.round)
          self.setup.table[stackIndex].add(newCard)
          print(self.setup.table)
  
          if self.deck.countDeck() == 40:
              crd = self.setup.table[-1]
              for c in crd:
                  self.setup.table[-1].removeStack(c)
          print(self.setup.table)
          #continue game prompting for new stack choice
          self.stackMatches(deck, self.setup)
  </code></pre>
  <p>The error I am getting is &quot;TypeError: 'Stack' object is not iterable&quot; specifically pertaining to the for loop in the following snippet:</p>
  <pre><code>        if self.deck.countDeck() == 40:
              crd = self.setup.table[-1]
              for c in crd:
                  self.setup.table[-1].removeStack(c)
  </code></pre>
  <p>I realize the removal logic is incorrect to begin with, but I will still need to iterate through list crd and am unsure what the workaround would be for this issue or how I would restructure my code to accomplish what I need while still utilizing best practices. I also tried changing my for loop to something like the following, resulting in the same error:</p>
  <pre><code>for c.cards in crd:
  </code></pre>
  <pre><code>for c[0] in crd:
  </code></pre>