반응형
You get any card as an argument. Your task is to return the suit of this card (in lowercase).
Our deck (is preloaded):
DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',
'2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD',
'2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH',
'2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC']
('3C') -> return 'clubs'
('3D') -> return 'diamonds'
('3H') -> return 'hearts'
('3S') -> return 'spades'
Solution:
def define_suit(card):
return {"C": "clubs", "D": "diamonds", "H": "hearts", "S": "spades"}[card[-1]]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1218. Remove First and Last Character (0) | 2022.12.18 |
---|---|
1217. Regexp Basics - is it a digit? (0) | 2022.12.17 |
1215. Is it even? (0) | 2022.12.15 |
1214. Find the position! (0) | 2022.12.14 |
1213. Exclamation marks series #1: Remove an exclamation mark from the end of string (0) | 2022.12.13 |