Created
August 4, 2015 13:45
-
-
Save bekatom/3904e407b08309ec3583 to your computer and use it in GitHub Desktop.
Custom card shuffle withouy shuffle method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import randrange | |
| class Card(): | |
| def __init__(self, rank, suit): | |
| self.rank = rank | |
| self.suit = suit | |
| card_list = [Card("HEARTS", 4), | |
| Card("HEARTS", 6), | |
| Card("DIAMONDS", 3), | |
| Card("DIAMONDS", 1), | |
| Card("DIAMONDS", 9) | |
| ] | |
| def my_shuffle(card_list): | |
| for i, card in enumerate(card_list): | |
| index = randrange(0, len(card_list)) | |
| card1 = card_list[i] | |
| card2 = card_list[index] | |
| card_list[i] = card2 | |
| card_list[index] = card1 | |
| return card_list | |
| my_shuffle(card_list) | |
| for card in card_list: | |
| print "Rank %s Suit %s " % (card.rank, card.suit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment