Spaces:
Sleeping
Sleeping
Delete convert2list.ipynb
Browse files- convert2list.ipynb +0 -84
convert2list.ipynb
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": 2,
|
| 6 |
-
"id": "b52e9a66-a8e9-4f56-91fd-8564b5b636fc",
|
| 7 |
-
"metadata": {},
|
| 8 |
-
"outputs": [],
|
| 9 |
-
"source": [
|
| 10 |
-
"# import nbimporter\n",
|
| 11 |
-
"import nbimporter\n",
|
| 12 |
-
"from Text2List import text_to_list\n",
|
| 13 |
-
"def convert_to_list(text, text_list):\n",
|
| 14 |
-
" matched_words = []\n",
|
| 15 |
-
" unmatched_text = '' # To accumulate unmatched characters\n",
|
| 16 |
-
"\n",
|
| 17 |
-
" # Sort text_list by length in descending order to prioritize longest matches first\n",
|
| 18 |
-
" text_list_sorted = sorted(text_list, key=len, reverse=True)\n",
|
| 19 |
-
"\n",
|
| 20 |
-
" while text:\n",
|
| 21 |
-
" matched = False\n",
|
| 22 |
-
" for word in text_list_sorted:\n",
|
| 23 |
-
" if text.startswith(word):\n",
|
| 24 |
-
" # Add any accumulated unmatched text before appending the matched word\n",
|
| 25 |
-
" if unmatched_text:\n",
|
| 26 |
-
" matched_words.append(unmatched_text)\n",
|
| 27 |
-
" unmatched_text = '' # Reset unmatched text accumulator\n",
|
| 28 |
-
"\n",
|
| 29 |
-
" matched_words.append(word)\n",
|
| 30 |
-
" text = text[len(word):] # Remove the matched part from text\n",
|
| 31 |
-
" matched = True\n",
|
| 32 |
-
" break\n",
|
| 33 |
-
"\n",
|
| 34 |
-
" if not matched:\n",
|
| 35 |
-
" # Accumulate unmatched characters\n",
|
| 36 |
-
" unmatched_text += text[0]\n",
|
| 37 |
-
" text = text[1:]\n",
|
| 38 |
-
"\n",
|
| 39 |
-
" # If there's any remaining unmatched text, add it to the result\n",
|
| 40 |
-
" if unmatched_text:\n",
|
| 41 |
-
" matched_words.append(unmatched_text)\n",
|
| 42 |
-
"\n",
|
| 43 |
-
" # Join matched words and unmatched text with a space\n",
|
| 44 |
-
" result = ' '.join(matched_words)\n",
|
| 45 |
-
" return result\n",
|
| 46 |
-
" \n",
|
| 47 |
-
"# text = \"जीरोएकदोतीनचारपांचछहसातआठनौदसजीरोएकदोतीनचारपांच\"\n",
|
| 48 |
-
"\n",
|
| 49 |
-
"# if __name__==\"__main__\":\n",
|
| 50 |
-
"# converted=convert_to_list(text, text_to_list())\n",
|
| 51 |
-
"# print(converted)"
|
| 52 |
-
]
|
| 53 |
-
},
|
| 54 |
-
{
|
| 55 |
-
"cell_type": "code",
|
| 56 |
-
"execution_count": null,
|
| 57 |
-
"id": "98835c96-2949-4e78-8d1e-c8623d5dcb00",
|
| 58 |
-
"metadata": {},
|
| 59 |
-
"outputs": [],
|
| 60 |
-
"source": []
|
| 61 |
-
}
|
| 62 |
-
],
|
| 63 |
-
"metadata": {
|
| 64 |
-
"kernelspec": {
|
| 65 |
-
"display_name": "Python 3 (ipykernel)",
|
| 66 |
-
"language": "python",
|
| 67 |
-
"name": "python3"
|
| 68 |
-
},
|
| 69 |
-
"language_info": {
|
| 70 |
-
"codemirror_mode": {
|
| 71 |
-
"name": "ipython",
|
| 72 |
-
"version": 3
|
| 73 |
-
},
|
| 74 |
-
"file_extension": ".py",
|
| 75 |
-
"mimetype": "text/x-python",
|
| 76 |
-
"name": "python",
|
| 77 |
-
"nbconvert_exporter": "python",
|
| 78 |
-
"pygments_lexer": "ipython3",
|
| 79 |
-
"version": "3.11.7"
|
| 80 |
-
}
|
| 81 |
-
},
|
| 82 |
-
"nbformat": 4,
|
| 83 |
-
"nbformat_minor": 5
|
| 84 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|