def make_sorted_deck():
''' Return a sorted deck of cards. Each card is
represented by a string as follows:
"queen of hearts". The cards are ordered by rank and then suit within rank.
:return: The sorted deck of cards, as a list of strings
EXAMPLE: make_sorted_deck() == ['2 of spades', '2 of hearts', '2 of clubs', ..., 'ace of clubs', 'ace of diamonds'] '''
#Hint: Use the previous functions and two nested for loops.
sorted_deck = []
for i in get_ranks():
for j in get_suits():
sorted_deck.append("{0} of {1}".format(i,j))
return sorted_deck
print(make_sorted_deck())
def shuffle(deck):
''' Randomly shuffle the cards in deck into a newly created deck of cards (list).
:param: deck: A deck of cards
:return: A new list, consisting of a random shuffle of deck.
EXAMPLE: shuffle(['2 of hearts', '3 of diamonds', 'jack of spades', '2 of clubs']) could return ['jack of spades', '3 of diamonds', '2 of hearts', '2 of clubs']
#REQUIREMENTS: Please implement the following algorithm: Use a while loop to repeatedly pick a random card from deck, remove it, and add it to a newly created list. '''
Как бы перетасовать список, созданный make_sorted_deck()
?Как перетасовать список в Python
Я знаю, что есть функция, которую я могу импортировать, чтобы перетасовать колоду, но я должен сделать это, чтобы вынуть 1 случайную карту и добавить ее в новый список, чтобы перетасовать список.
Возможный дубликат [Лучший способ рандомизации список строк в Python] (http://stackoverflow.com/questions/1022141/best-way-to-randomize-a-list-of-strings-in-python) – GingerPlusPlus
@GingerPlusPlus Я думаю, что они отличаются друг от друга. См. Окончание комментария OP – Pynchia