{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b340abe0-1022-48c0-916e-bc9a7a2fca91",
   "metadata": {},
   "source": [
    "# Woche 21\n",
    "\n",
    "SS 2026, Klausurvorbereitung Nachschreibeklausur\n",
    "\n",
    "Ansatz: Wir erstellen eine Aufgabenstellungen, die eine Vielzahl von einzelnen kleinen Aufgaben und -Lösungen erlaubt. \n",
    "Wer die kann, wird der Klausur mit großer Freude entgegenblicken!\n",
    "\n",
    "Vorgehen, wenn Sie nicht weiterkommen: Fragen Sie auch eine KI, Sie werden ein Programm bekommen. Verstehen sie das Programm. Fragen Sie öfters, ggf. auch explizit nach unterschiedlichen Lösungen, vergleichen Sie die verschiedenen Lösungen. Schließen Sie die KI, schlafen Sie eine Nacht darüber. Versuchen Sie am nächsten Morgen, die Lösung ohne KI selbst hinzubekommen."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "913fb0d4",
   "metadata": {},
   "source": [
    "gegeben:\n",
    "* Funktion n:1, z.B. Modulnummer - Prüfung.\n",
    "\n",
    "gesucht:\n",
    "* inverse Abbildung 1:n, Prüfung - Menge von Modulnummern"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "21a7531c-e64e-4933-85d4-d702960fdf7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "klausur = { \"wif110\": \"Programmieren 1\",   \"aif120\": \"Programmieren 1\", \"wif640\": \"Seminar\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "050e29a5-ef1c-4985-b5af-b62d635bbf55",
   "metadata": {},
   "outputs": [],
   "source": [
    "kinvers = { \"Programmieren 1\": [ \"wif110\", \"aif120\" ],  \"Seminar\": [ \"wif640\" ] }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1576af37-0437-4dfa-9006-05cf3b025f3a",
   "metadata": {},
   "source": [
    "Lösung 1:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f588814d-e90c-4154-b509-693fd114babb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ergebnis={'Programmieren 1': ['wif110', 'aif120'], 'Seminar': ['wif640']}\n"
     ]
    }
   ],
   "source": [
    "ergebnis = {}\n",
    "\n",
    "for k, v  in klausur.items():\n",
    "    # print( f\"{k=}, {v=}\")\n",
    "\n",
    "    if v not in ergebnis.keys():\n",
    "        ergebnis[v] = []\n",
    "\n",
    "    ergebnis[v].append( k )\n",
    "    \n",
    "    \n",
    "print( f\"{ergebnis=}\" )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8235cfd4-8d8c-4e60-8d70-04353b7e08ba",
   "metadata": {},
   "source": [
    "Lösung 2: Dicht `ergebnis` vorher schon initialisieren"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2f684650-6018-4f10-ab95-f51f779549b7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Programmieren 1', 'Seminar'}"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(klausur.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "861c4ea3-bcb2-4eaa-a7b2-e2ff2d083a20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Seminar': [], 'Programmieren 1': []}"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ergebnis = {  v: []   for v in set(klausur.values())   }\n",
    "ergebnis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "3a0baa59-3f5a-4672-ad70-27a08ad57807",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Seminar': ['wif640'], 'Programmieren 1': ['wif110', 'aif120']}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for k, v  in klausur.items():\n",
    "    ergebnis[v].append( k )\n",
    "ergebnis"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aac74d84",
   "metadata": {},
   "source": [
    "gegeben:\n",
    "* 2 Spalten einer Tabelle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ff4a1921",
   "metadata": {},
   "outputs": [],
   "source": [
    "stadt = [ \"Landshut\", \"Ulm\",\"Nürnberg\" ]\n",
    "einwohner_in_1000 = [ 70, 120, 500 ]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44ea747e",
   "metadata": {},
   "source": [
    "gesucht:\n",
    "* die Tabelle zeilenweise als eine Liste von Tupeln\n",
    "\n",
    "mit zip():"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "556037b4-3184-4e4b-94a7-b3a1ba1221c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Ellipsis"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14cbcaed-44f4-4621-bbb3-a40eea44b495",
   "metadata": {},
   "source": [
    "Ohne zip, Tipp: zwei Möglichkeiten, durch eine Liste durchzulaufen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5d38c9dc-376a-445c-883d-8ff2c2860225",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Landshut\n",
      "Ulm\n",
      "Nürnberg\n"
     ]
    }
   ],
   "source": [
    "for x in stadt:\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "681e1be8-7369-467b-9b5b-68acf4c407f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Landshut\n",
      "Ulm\n",
      "Nürnberg\n"
     ]
    }
   ],
   "source": [
    "for i in range( len( stadt ) ):\n",
    "    print( stadt[i] )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "ee7975f8-1593-46df-b274-87eedd576d70",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Landshut 70\n",
      "Ulm 120\n",
      "Nürnberg 500\n"
     ]
    }
   ],
   "source": [
    "for i in range( len( stadt ) ):\n",
    "    print( stadt[i] , einwohner_in_1000[i])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "345c20fc-c67e-433d-9c27-eb9faf24ff79",
   "metadata": {},
   "source": [
    "Und jetzt die Lösung selber machen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "38953ef4-bb61-4957-803d-e8524328d098",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Ellipsis"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stadt_einwohner = []\n",
    "\n",
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba4f0dbc-48ab-4b1b-bb97-5cab97c23d44",
   "metadata": {},
   "source": [
    "Ohne zip mit Comprehension:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "45c44ab0-4454-4b31-bbd8-f688e0a42e7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "stadt_einwohner = [ ... ]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ccb1435-8f47-45d7-9456-3a0b7cce3065",
   "metadata": {},
   "source": [
    "Test:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "a58e9474",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stadt_einwohner == [ (\"Landshut\", 70), (\"Ulm\", 120), (\"Nürnberg\", 500) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5eeb4792",
   "metadata": {},
   "source": [
    "gegeben: ein Dict mit Geburtsdatum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eeddb65e-a4f9-49f2-afd0-37094e54a277",
   "metadata": {},
   "outputs": [],
   "source": [
    "# gb ... geburtsdaten\n",
    "gb = {\n",
    "    \"Lovelace, Ada\": \"1815-12-10\",\n",
    "    \"Turing, Alan\": \"1912-06-23\",\n",
    "    \"Hopper, Grace\": \"1906-12-09\",\n",
    "    \"Zuse, Konrad\": \"1910-06-22\",\n",
    "    \"van Rossum, Guido\": \"1956-01-31\"\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "684144f2",
   "metadata": {},
   "source": [
    "Füge die folgenden Menschen dem Dict hinzu:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79467429",
   "metadata": {},
   "outputs": [],
   "source": [
    "menschen_1956 = [\n",
    "    (\"Steinmeier, Frank-Walter\", \"1956-01-05\"),\n",
    "    (\"Grönemeyer, Herbert\", \"1956-04-12\"),\n",
    "    (\"Hanks, Tom\", \"1956-07-09\")\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1366f3c3",
   "metadata": {},
   "source": [
    "Eine Liste aller in `gb` enthaltenen Namen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3ab81d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89feb672",
   "metadata": {},
   "source": [
    "Eine Liste aller in `gb` enthaltenen Datums-Strings:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b352fc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e9e2b21",
   "metadata": {},
   "source": [
    "Eine Liste aller in `gb` enthaltenen Jahre (ohne Duplikate):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93d2dbd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe90ec37",
   "metadata": {},
   "source": [
    "```\n",
    "\n",
    "Überführe das Geburtsdatum in eine besser verarbeitbare Struktur, Beispiel:\n",
    "\n",
    "```{code-cell} ipython3\n",
    "gb_key_liste = \n",
    "{ \"Lovelace, Ada\": [ \"1815\", \"12\", \"10\"],\n",
    "  \"Turing, Alan\": [ \"1912\", \"06\", \"23\" ] ,\n",
    "  ... }\n",
    "```\n",
    "\n",
    "und auch so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "78c5a9b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "gb_key_dict = { \"Lovelace, Ada\": { \"jjjj\": \"1815\", \"mm\": \"12\", \"tt\": \"10\" },\n",
    "  \"Turing, Alan\":  { \"jjjj\": \"1912\", \"mm\": \"06\", \"tt\": \"23\" } ,\n",
    "  ...: ... }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "578488b3",
   "metadata": {},
   "source": [
    "Auch die Namen wollen wir in Vorname und Familienname aufteilen, z.B. so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "a65881d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "gb_key_liste =  { (\"Lovelace\", \"Ada\"): [ \"1815\", \"12\", \"10\"],\n",
    "  (\"Turing\", \"Alan\"):  [ \"1912\", \"06\", \"23\" ] ,\n",
    "  ...: ... }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "296bfeb8",
   "metadata": {},
   "source": [
    "gesucht: ein dict, das zu jedem Jahr die zugehörigen Menschen angibt, z.B."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "bb2bf4e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "jahr_personen =  {\n",
    "    '1815': { ('Lovelace, Ada', '1815-12-10') },\n",
    "    '1956': {\n",
    "        ('van Rossum, Guido', '1956-01-31'),\n",
    "        ('Steinmeier, Frank-Walter', '1956-01-05'),\n",
    "        ('Grönemeyer, Herbert', '1956-04-12'),\n",
    "        ('Hanks, Tom', '1956-07-09') },\n",
    "    ...: ..., }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79fe6fe7-a401-45a4-950a-3e20c7e3f7d6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04054dc9-2cd5-418a-ba04-e751d814e847",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bdcaa03c-514d-468a-ab78-c761882b03b6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27d6e171-a383-4505-8509-baa2c26291d3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94984496-a442-428e-a2fb-b5bf23629ef0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "287139ca-78fb-42a7-8fab-a8b7340c45aa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "jupytext": {
   "default_lexer": "ipython3",
   "formats": "ipynb,md:myst"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
