(Python pls)Build a two dimensional array out of the following three lists. The
ID: 3888766 • Letter: #
Question
(Python pls)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"]
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
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.