fork download
  1. def janken(_):
  2. """
  3. :return:
  4. >>> janken('gpgpgppppg')
  5. 6
  6. >>> janken('ggggggggggggggg')
  7. 0
  8. >>> janken('ccpcpppcccpppcppcpcc')
  9. 10
  10. >>> janken('ggcgcgcggggcpgcggcgcggggcgcgcc')
  11. 0
  12. """
  13. h = {}
  14. for _ in _:
  15. if h.get(_):
  16. h[_] += 1
  17. else:
  18. h[_] = 1
  19.  
  20. if len(h) != 2: return 0
  21. if not h.get('c'): return h['p']
  22. if not h.get('g'): return h['c']
  23. if not h.get('p'): return h['g']
  24.  
  25.  
  26. if __name__ == '__main__':
  27. import doctest
  28.  
  29. doctest.testmod()
Success #stdin #stdout 0.05s 11928KB
stdin
Standard input is empty
stdout
Standard output is empty