I had a mental breakdown

This commit is contained in:
2024-12-06 10:43:44 +01:00
parent a1e0e21582
commit 4b84516d52
2 changed files with 167 additions and 5 deletions

View File

@ -43,6 +43,112 @@
"\n",
"print([list(map(sum,i)) for i in lines])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A leghosszab szó: 'gépidőelszámolást', ami 17 karakterből áll\n"
]
}
],
"source": [
"lines = []\n",
"with open(\"igazi.txt\") as f:\n",
" lines.extend(f.readlines())\n",
"lines = list(set([i.strip() for i in lines]))\n",
"lenoflines = [len(i) for i in lines]\n",
"\n",
"\n",
"print(f\"A leghosszab szó: '{lines[lenoflines.index(max(lenoflines))]}', ami {max(lenoflines)} karakterből áll\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"65 90\n"
]
}
],
"source": [
"print(ord('A'), ord('Z'))"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Blackburn Rovers 45\n",
"Wolverhampton Wanderers 38\n",
"Fulham FC 55\n",
"Aston Villa 39\n",
"Liverpool FC 43\n",
"Sunderland AFC 45\n",
"Queens Park Rangers 43\n",
"Bolton Wanderers 42\n",
"Wigan Athletic 41\n",
"Norwich City 47\n",
"Newcastle United 48\n",
"Arsenal FC 58\n",
"Stoke City 44\n",
"Chelsea FC 60\n",
"West Bromwich Albion 40\n",
"Manchester United 71\n",
"Manchester City 74\n",
"Swansea City 46\n",
"Tottenham Hotspur 58\n",
"Everton FC 47\n"
]
}
],
"source": [
"class matches:\n",
" def __init__(self):\n",
" pass\n",
"\n",
"A = []\n",
"with open(\"pl.txt\") as f:\n",
" for _ in range(6):\n",
" next(f)\n",
" for i in f.readlines():\n",
" match = matches()\n",
" line = i.strip().split('\\t')\n",
" match.ford = line[0]\n",
" match.hteam = line[1]\n",
" match.vteam = line[2]\n",
" match.hgoal = int(line[3])\n",
" match.vgoal = int(line[4])\n",
" A.append(match)\n",
"\n",
"teams = {}\n",
"for i in A:\n",
" if i.hteam in teams.keys():\n",
" teams[i.hteam] += i.hgoal\n",
" else:\n",
" teams.update({i.hteam : i.hgoal})\n",
" if i.vteam in teams.keys():\n",
" teams[i.vteam] += 1 \n",
" else:\n",
" teams.update({i.vteam : 1})\n",
"\n",
"print(\"\\n\".join(f\"{i.ljust(25)} {j}\" for i, j in teams.items()))"
]
}
],
"metadata": {

View File

@ -33,15 +33,71 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>fordulo</th>\n",
" <th>sum</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5</td>\n",
" <td>38</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" fordulo sum\n",
"0 5 38"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.read_csv(\"pl.txt\", skiprows=6, sep=\"\\t\", names=[\"fordulo\", \"hcsapat\", \"vcsapat\", \"hgol\", \"vgol\"])\n",
"\n",
"df.groupby(\"fordulo\").count()[\"hcsapat\"]\n",
"\n",
"goals_round = df.groupby(\"fordulo\")[[\"hgol\", \"vgol\"]].sum().sort_values(\"hgol\", ascending=False)[:1]\n",
"goals_round[\"sum\"] = goals_round[\"hgol\"] + goals_round[\"vgol\"]\n",
"\n",
"goals_round.reset_index()[[\"fordulo\", \"sum\"]]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -55,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,