An example of the answer to the reference question of the study session. In python.

Another example of the answer to the reference question (http://qiita.com/items/cbc3af152ee3f50a822f) of the study session (http://atnd.org/events/30285) scheduled to be held on 7/6 (Friday). I decided to write in a language that hasn't come out yet, so python.

poka.py


# -*- coding: utf-8 -*-
import re

Q=[ "DASAD10CAHA", "S10HJDJCJSJ",
  "S10HAD10DAC10", "HJDJC3SJS3",
  "S3S4H3D3DA", "S2HADKCKSK",
  "SASJDACJS10", "S2S10H10HKD2",
  "CKH10D10H3HJ", "C3D3S10SKS2",
  "S3SJDAC10SQ", "C3C9SAS10D2"]

def hand_name( d ):
  if d==[1,4]:  return '4K'
  if d==[2,3]:  return 'FH'
  if d==[1,1,3]:  return '3K'
  if d==[1,2,2]:  return '2P'  
  if d==[1,1,1,2]:  return '1P'
  return '--'

def rank_dist( ranks ):
  map={}
  for r in ranks:
    if r in map:
      map[r]+=1
    else:
      map[r]=1
  dist = map.values()
  dist.sort()
  return dist
  
p = re.compile( r"[SHDC]([JQKA\d]+)"*5)
for q in Q:
  mo=p.match( q )
  ranks=sorted( [ mo.group( x+1 ) for x in range(5) ] )
  dist=rank_dist( ranks )
  print hand_name( dist )

I have almost no experience with python, so I think I can probably write much better. Especially, the rank_dist function feels very stupid.

There was such a freshness as I had to write a return and I wondered if I could omit the parentheses.

The list comprehension notation is the real thrill, so I have to use it.

Recommended Posts

An example of the answer to the reference question of the study session. In python.
How to know the internal structure of an object in Python
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences
"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings
How to get the number of digits in Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify
"Book to train programming skills to fight in the world" Python code answer example --2.6 palindrome
"A book to train programming skills to fight in the world" Python code answer example --1.2 Count the number of the same characters
"Book to train programming skills to fight in the world" Python code answer example --2.4 Splitting the list
In the python command python points to python3.8
"Book to train programming skills to fight in the world" Python code answer example --2.7 intersecting nodes
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
An alternative to `pause` in Python
An easy way to hit the Amazon Product API in Python
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
The 15th offline real-time how to write reference problem in Python
How to check the memory size of a variable in Python
Output the contents of ~ .xlsx in the folder to HTML with Python
I wrote the code to write the code of Brainf * ck in python
How to check the memory size of a dictionary in Python
[Python] Explains how to use the format function with an example
The 14th offline real-time how to write reference problem in python
Various ways to create an array of numbers from 1 to 10 in Python.
The 18th offline real-time how to write reference problem in Python
"A book to train programming skills to fight in the world" Python code answer example --3.1 Three stacks
Check the behavior of destructor in Python
The story of an error in PyOCR
The result of installing python in Anaconda
To reference environment variables in Python in Blender
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
Practical example of Hexagonal Architecture in Python
[Question] How to use plot_surface of python
[Python] I tried to summarize the set type (set) in an easy-to-understand manner.
The 17th offline real-time how to write reference problem implemented in Python
Comparing the basic grammar of Python and Go in an easy-to-understand manner
Python Note: When you want to know the attributes of an object
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to color a part of an Excel string in Python
Open an Excel file in Python and color the map of Japan
I want to leave an arbitrary command in the command history of Shell
I made a program to check the size of a file in Python
"A book to train programming skills to fight in the world" Python code answer example --1.1 Duplicate character string
[Question] In sk-learn random forest regression, an error occurs when the number of parallels is set to -1.
Various ways to read the last line of a csv file in Python
How to pass the execution result of a shell command in a list in Python
How to use the C library in Python
Python constants like None (according to the reference)
[Python] I want to know the variables in the function when an error occurs!
[Python] Sort the list of pathlib.Path in natural sort
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
I want to use Python in the environment of pyenv + pipenv on Windows 10
Summary of how to import files in Python 3
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
Get the caller of a function in Python