import random
from Card import *

class Deck:
    """Definition of the Deck class.  Each Deck is just a list of cards."""

    def __init__(self):
        """Return a new deck of cards."""
        self._cards = []
        for suit in Card.SUITS:
            for rank in Card.RANKS:
                c = Card(rank, suit)
                self._cards.append(c)

    def shuffle(self):
        """Shuffle the cards."""
        random.shuffle(self._cards)

    def deal(self):
        """Remove and return the top card, or None
        if the deck is empty."""
        if len(self) == 0:
            return None
        else:
            return self._cards.pop(0)

    def __len__(self):
        """Returns the number of cards left in the deck."""
        return len(self._cards)

    def __str__(self):
        result = ""
        for c in self._cards:
            result = result + str(c) + "\n"
        return result
