{ "cells": [ { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "# takes as input, hand, and returns a \"dictionary\" whose keys are\n", "# the ranks and the values are the number of cards in the hand for \n", "# the given rank\n", "def process_ranks(hand):\n", "\tdrank = {}\n", "\tfor n in range(2,15):\n", "\t\tdrank[n] = 0\n", "\tcards = hand.split(\":\")\n", "\tconvert = {'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'t':10,'j':11,'q':12,'k':13,'a':14}\n", "\tfor card in cards:\n", "\t\trank = card[0]\n", "\t\tdrank[convert[rank]] = drank[convert[rank]] + 1\n", "\treturn drank" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{2: 2, 3: 1, 4: 1, 5: 0, 6: 1, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0}\n" ] } ], "source": [ "d = process_ranks(\"2s:2c:4s:3c:6d\")\n", "print(d)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# takes as input, hand, and returns a \"dictionary\" whose keys are\n", "# the suits and the values are the number of cards in the hand for \n", "# the given suit\n", "def process_suits(hand):\n", "\tdsuit = {'s':0, 'c': 0, 'h':0, 'd':0}\n", "\tcards = hand.split(\":\")\n", "\tfor card in cards:\n", "\t\tsuit = card[1]\n", "\t\tdsuit[suit] = dsuit[suit] + 1\n", "\treturn dsuit\n", "\n", "#2s:5s:4s:3s:6s" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'s': 2, 'c': 2, 'h': 0, 'd': 1}\n" ] } ], "source": [ "d = process_suits(\"2s:5c:4s:3c:6d\")\n", "print(d)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xs = [10,11,12,13,14,15,16,17,18,19,20]\n", "list(range(10,21))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "drank = {}\n", "for n in range(2,15):\n", " drank[n] = 0\n", "\n", "dsuit = {'s':0, 'c': 0, 'h':0, 'd':0}\n", "\n", "dsuit = {}\n", "for s in ['c','d','h','s']:\n", " dsuit[s] = 0" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['2s', '5s', '4s', '3s', '6s']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"2s:5s:4s:3s:6s\".split(':')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "convert = {'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'t':10,'j':11,'q':12,'k':13,'a':14}" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "convert['q']" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" } }, "nbformat": 4, "nbformat_minor": 2 }