-
Notifications
You must be signed in to change notification settings - Fork 0
/
Codewars_11.py
19 lines (19 loc) · 1.02 KB
/
Codewars_11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#7 kyu https://www.codewars.com/kata/5acbc3b3481ebb23a400007d
#Determine if the poker hand is flush
#DESCRIPTION:
#Determine if the poker hand is flush, meaning if the five cards are of the same suit.
#Your function will be passed a list/array of 5 strings, each representing a poker card in
#the format "5H" (5 of hearts), meaning the value of the card followed by the initial of its
#suit (Hearts, Spades, Diamonds or Clubs). No jokers included.
#Your function should return true if the hand is a flush, false otherwise.
#The possible card values are 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
#Examples
#["AS", "3S", "9S", "KS", "4S"] ==> true
#["AD", "4S", "7H", "KS", "10S"] ==> false
#three approaches
#compare the slice to the string
[print('True') for i in a if i[1]=='S']
#index the first slice and then compare every slice to it.
[print('True') for i in a if i[1]==a[0][1]]
#dictionary approach, make a dictionary, then make a set of the values and if the length is 1 print True.
'True' if len(set(dict(a).values()))==1 else 'False'