(Begin quote) 400: Name: Anonymous @ teary eyes. (Gifu Castle): 2011/10/15 (Sat) 18: 51: 50.10 ID: eMBuD7fo0 I picked it up from a certain place. "If you can't do this in 10 minutes, be aware of the painful fact that you can't really program."
Create a function that returns the distributed cards as an array given the number of people and the cards. The cards are dealt in order from the front of the given character string, the number of cards dealt is equal, and the remainder is ignored. (End of citation) http://qiita.com/hisui@github/items/b47c411437d60440a605
I couldn't understand the problem clearly, but it looks like this: It took about 5 minutes.
def card_distributer(number, cards):
card_list = [ [] for i in range(number) ]
while ( len(cards) // number ) > 0:
for i in range(number):
card_list[i].append(cards.pop(0))
return card_list
print card_distributer(3,['SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'SJ', 'SQ', 'SK'])
output
[ ['SA', 'S4', 'S7', 'S10'], ['S2', 'S5', 'S8', 'SJ'], ['S3', 'S6', 'S9', 'SQ'] ]
Recommended Posts