File size: 1,265 Bytes
998b6cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"\n",
"def get_code_pairs(directory):\n",
" pairs = []\n",
" for filename in os.listdir(os.path.join(directory, \"python\")):\n",
" if filename.endswith(\".py\"):\n",
" rust_filename = filename.replace(\".py\", \".rs\")\n",
" python_path = os.path.join(directory, \"python\", filename)\n",
" rust_path = os.path.join(directory, \"rust\", rust_filename)\n",
" if os.path.exists(rust_path):\n",
" with open(python_path, \"r\") as f:\n",
" python_code = f.read()\n",
" with open(rust_path, \"r\") as f:\n",
" rust_code = f.read()\n",
" pairs.append((python_code, rust_code))\n",
" return pairs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pairs = get_code_pairs(\".\")\n",
"df = pd.DataFrame(pairs, columns=[\"Python\", \"Rust\"])\n",
"df"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
} |