So I have a list hand whose data is something like this ['AS', 'AD', 'AC', 'CH', 'CS']. Now I have to find the first character of each element in the list and see if there are 3 identical letters and 2 identical letters or not.
Note: they must all be in order though.. like always x,x,x,y,y or y,y,x,x,x. Any other combination, like x,y,y,x,x or x,y,x,y,x, will return False
So for example
['AS', 'AD', 'AC', 'CH', 'CS'] returns True because there are 3 A and 2 C.
['AS', 'SD', 'SC', 'CH', 'CS'] returns False because the order is not right
['CS', 'CD', 'AC', 'AH', 'AS'] returns True because there are 3 A and 2 C
['AS', 'CD', 'DC', 'AH', 'CS'] returns False because none of the characters appear 3 times and 2 times.
Here is my code so far, which doesn't work...
hand = ['AS', 'AD', 'AC', 'CH', 'CS']
updated_hands = list([x[1] for x in hand])
if ((updated_hands[0] == updated_hands[1] == updated_hands[2]) or (updated_hands[2] == updated_hands[3] == updated_hands[4])) and ((updated_hands[3] == updated_hands[4]) or (updated_hands[0] == updated_hands[1])):
print('True')
else:
print('False')
What changes should I make to this?
x[0], right?