score:92 time:26:17
The point this time is --What is duplicated in the list ――How many duplicates are there? Was the point.
python
loop_count = int(input())
for i in range(loop_count):
numbers = list(input())#Point 1
double = [x for x in set(numbers) if numbers.count(x) > 1]#Point 2
if len(dup) == 2:
print("Two Pair")
elif len(dup) == 0:
print("No Pair")
else:
check = numbers.count(dup[0])#Point 3
if check == 4:
print("Four Card")
elif check == 3:
print("Three Card")
elif check == 2:
print("One Pair")
else:
pass
Check for duplicates
numbers = [1, 1, 4, 5, 1, 4, 4, 6, 4, 9]
double = [x for x in set(numbers) if numbers.count(x) > 1]
#Described in list comprehension
set(numbers) ---> {1, 4, 5, 6, 9}
#Arrayed by[numbers]It judges what kind of value there is in and returns it with [Set] of a unique list.
#For this reason, for x for x{1, 4, 5, 6, 9}Is entered and processed.
numbers.count(x)
> numbers.count(1) ---> 3
> numbers.count(4) ---> 4
> numbers.count(5) ---> 1
> numbers.count(6) ---> 1
> numbers.count(9) ---> 1
#Array[numbers]In{1, 4, 5, 6, 9}I'm checking how many of each are included.
numbers.count(x) > 1
#So, if the number of duplicates is greater than 1, insert the current value into x and add it as an array.
#set{1, 4, 5, 6, 9}Each number is list[number]If there are more than 1(If 2 or more)Add to list. We are doing the processing.
Recommended Posts