From 13aafd858b4aec81b8511aaaea1b3369fb125e1f Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Wed, 24 Sep 2025 10:50:46 +0300 Subject: [PATCH] add solution --- exercises/match_tarots/match_tarots.ipynb | 95 +++++++++++++++++++++-- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/exercises/match_tarots/match_tarots.ipynb b/exercises/match_tarots/match_tarots.ipynb index c35f220..4df1b59 100644 --- a/exercises/match_tarots/match_tarots.ipynb +++ b/exercises/match_tarots/match_tarots.ipynb @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "id": "cf05b9c4", "metadata": {}, "outputs": [ @@ -36,9 +36,9 @@ "output_type": "stream", "text": [ "-- Deck 1: --\n", - " ['The Lovers', 'Temperance', 'The Emperor', 'The Sun', 'The Fool', 'The Chariot', 'Death', 'Strength', 'Justice', 'The Star', 'Judgement', 'The World', 'The Tower', 'The Hanged Man', 'The Empress', 'The Hermit', 'The Devil', 'The High Priestess', 'The Moon', 'The Hierophant', 'Wheel of Fortune', 'The Magician']\n", + " ['The Chariot', 'Strength', 'The Lovers', 'The Moon', 'The Magician', 'Judgement', 'Wheel of Fortune', 'The Tower', 'The Hierophant', 'The Star', 'The Fool', 'The Empress', 'The Hanged Man', 'The Sun', 'The Emperor', 'The High Priestess', 'The Hermit', 'The World', 'Death', 'Temperance', 'Justice', 'The Devil']\n", "-- Deck 2: --\n", - " ['The Fool', 'Death', 'The Hermit', 'Strength', 'The Moon', 'Wheel of Fortune', 'Judgement', 'The Lovers', 'The Star', 'The Hanged Man', 'The Empress', 'The Emperor', 'The Magician', 'The Tower', 'The Hierophant', 'The Chariot', 'The High Priestess', 'Temperance', 'The World', 'The Devil', 'The Sun', 'Justice']\n" + " ['The Devil', 'The Moon', 'The Hanged Man', 'The Magician', 'The Chariot', 'The World', 'Temperance', 'Justice', 'The Emperor', 'The Empress', 'The Hermit', 'The Lovers', 'The Tower', 'Judgement', 'Wheel of Fortune', 'Death', 'The High Priestess', 'The Sun', 'The Hierophant', 'The Fool', 'Strength', 'The Star']\n" ] } ], @@ -69,11 +69,88 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "48eb31e2", + "execution_count": 15, + "id": "a5fb5054-5c4a-4973-9e72-300003d69a53", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "deck2 = dict((card, idx) for (idx, card) in enumerate(deck2))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "dd077f0a-c858-4257-8d72-a3dd4844074f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{('The Hierophant', 18): 0,\n", + " ('The Magician', 3): 1,\n", + " ('The Hanged Man', 2): 2,\n", + " ('The Lovers', 11): 3,\n", + " ('Judgement', 13): 4,\n", + " ('The Sun', 17): 5,\n", + " ('The High Priestess', 16): 6,\n", + " ('The Hermit', 10): 7,\n", + " ('The Star', 21): 8,\n", + " ('Temperance', 6): 9,\n", + " ('The World', 5): 10,\n", + " ('The Fool', 19): 11,\n", + " ('Strength', 20): 12,\n", + " ('The Devil', 0): 13,\n", + " ('Justice', 7): 14,\n", + " ('The Emperor', 8): 15,\n", + " ('The Moon', 1): 16,\n", + " ('Wheel of Fortune', 14): 17,\n", + " ('The Tower', 12): 18,\n", + " ('Death', 15): 19,\n", + " ('The Empress', 9): 20,\n", + " ('The Chariot', 4): 21}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "deck2" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "48eb31e2", + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'The Chariot'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[19], line 9\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mmatch\u001b[39;00m\u001b[38;5;241m.\u001b[39madd(idx, deck2[card1])\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m match\n\u001b[0;32m----> 9\u001b[0m match \u001b[38;5;241m=\u001b[39m \u001b[43mmatch_tarot\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdeck1\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdeck2\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mmatch\u001b[39;00m\n", + "Cell \u001b[0;32mIn[19], line 6\u001b[0m, in \u001b[0;36mmatch_tarot\u001b[0;34m(deck1, deck2)\u001b[0m\n\u001b[1;32m 4\u001b[0m match \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m()\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m (card1, idx) \u001b[38;5;129;01min\u001b[39;00m deck1\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28;01mmatch\u001b[39;00m\u001b[38;5;241m.\u001b[39madd(idx, \u001b[43mdeck2\u001b[49m\u001b[43m[\u001b[49m\u001b[43mcard1\u001b[49m\u001b[43m]\u001b[49m)\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m match\n", + "\u001b[0;31mKeyError\u001b[0m: 'The Chariot'" + ] + } + ], + "source": [ + "def match_tarot(deck1, deck2):\n", + " deck1 = dict((card, idx) for (idx, card) in enumerate(deck1))\n", + " deck2 = dict((card, idx) for (idx, card) in enumerate(deck2))\n", + " match = set()\n", + " for (card1, idx) in deck1.items():\n", + " if card1 in deck2.keys()\n", + " match.add(idx, deck2[card1])\n", + " return match\n", + "\n", + "match = match_tarot(deck1, deck2)\n", + "match" + ] }, { "cell_type": "code", @@ -81,7 +158,9 @@ "id": "509dda71", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "match ={}\n" + ] } ], "metadata": { @@ -100,7 +179,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.13.6" } }, "nbformat": 4, -- 2.39.5