Build a two dimensional array out of the following three lists. The array will r
ID: 3888536 • Letter: B
Question
Build a two dimensional array out of the following three lists. The array will represent a deck of cards. The values in dCardValues correspond to the card names in dCardNames. Note that when you make an array all data types must be the same. Apply dSuits to dCardValues and dCardNames by assigning a suit to each set of 13 elements.
dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']
dSuits = ["Clubs","Spades","Diamonds","Hearts"]
Once you have this two dimensional array, you should shuffle it either by function or by code to produce a shuffled deck of cards. After that apply the three sorts (Selection, Insertion and Bubble) ,to the two dimensional array returning it to it original state as listed above. This assignment will require some problem solving ability.
Explanation / Answer
dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']
dSuits = ["Clubs","Spades","Diamonds","Hearts"]
#combines dCardValues with dCardNames
def mergeCardWithValues(dCardNames, dCardValues):
card_dic={}
#iterating through each element of cardnae
for i in range(len(dCardNames)):
card_dic[dCardNames[i]]= dCardValues[i]
return card_dic
deck=[] #empty deck
#add card_dic to each suit
for suit in dSuits:
suit_arr=[suit,mergeCardWithValues(dCardNames, dCardValues)] #suit and card_dic
deck.append(suit_arr) #adding suit_arr to deck
print deck #print deck
dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']
dSuits = ["Clubs","Spades","Diamonds","Hearts"]
#combines dCardValues with dCardNames
def mergeCardWithValues(dCardNames, dCardValues):
card_dic={}
#iterating through each element of cardnae
for i in range(len(dCardNames)):
card_dic[dCardNames[i]]= dCardValues[i]
return card_dic
deck=[] #empty deck
#add card_dic to each suit
for suit in dSuits:
suit_arr=[suit,mergeCardWithValues(dCardNames, dCardValues)] #suit and card_dic
deck.append(suit_arr) #adding suit_arr to deck
print deck #print deck
[['Clubs', {'A': '14', '10': '10', 'K': '13', 'J': '11', 'Q': '12', '3': '3', '2': '2', '5': '5', '4': '4', '7': '7', '6': '6', '9': '9', '8': '8'}], ['Spades', {'A': '14', '10': '10', 'K': '13', 'J': '11', 'Q': '12', '3': '3', '2': '2', '5': '5', '4': '4', '7': '7', '6': '6', '9': '9', '8': '8'}], ['Diamonds', {'A': '14', '10': '10', 'K': '13', 'J': '11', 'Q': '12', '3': '3', '2': '2', '5': '5', '4': '4', '7': '7', '6': '6', '9': '9', '8': '8'}], ['Hearts', {'A': '14', '10': '10', 'K': '13', 'J': '11', 'Q': '12', '3': '3', '2': '2', '5': '5', '4': '4', '7': '7', '6': '6', '9': '9', '8': '8'}]]Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.