{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "efe6aed4",
   "metadata": {},
   "source": [
    "# 12-12 · Częstotliwość słów\n",
    "\n",
    "Praktyka do sekcji [„Project: Text Analyzer and Word Frequency”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9213ec4",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Liczenie częstotliwości słów i znalezienie najczęściej występującego słowa przez max(key=...)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dbe12bea",
   "metadata": {},
   "source": [
    "## Pro input() w tym laptopie\n",
    "\n",
    "Ten laptop jest automatyczny, więc `input()` tymczasowo zastąpione wcześniej przygotowanymi odpowiedziami."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f6ced3b2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:37.670662Z",
     "iopub.status.busy": "2026-08-17T16:38:37.670547Z",
     "iopub.status.idle": "2026-08-17T16:38:37.688419Z",
     "shell.execute_reply": "2026-08-17T16:38:37.688104Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['Python is great and python is fun'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a1d89a6",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5e198025",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:37.689881Z",
     "iopub.status.busy": "2026-08-17T16:38:37.689766Z",
     "iopub.status.idle": "2026-08-17T16:38:37.692796Z",
     "shell.execute_reply": "2026-08-17T16:38:37.692283Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Введите текст: Python is great and python is fun\n",
      "{'python': 2, 'is': 2, 'great': 1, 'and': 1, 'fun': 1}\n",
      "Самое частое слово: python — 2 раз(а)\n"
     ]
    }
   ],
   "source": [
    "text = input(\"Введите текст: \")\n",
    "normalized = text.lower().split()\n",
    "\n",
    "counts = {}\n",
    "for word in normalized:\n",
    "    counts[word] = counts.get(word, 0) + 1\n",
    "\n",
    "samoe_chastoe = max(counts, key=counts.get)\n",
    "\n",
    "print(counts)\n",
    "print(\"Самое частое слово:\", samoe_chastoe, \"—\", counts[samoe_chastoe], \"раз(а)\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
