Skip to content

Commit 0497d32

Browse files
String reversing and slicing.
1 parent f0976b4 commit 0497d32

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

string_coding.ipynb

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": [],
7+
"authorship_tag": "ABX9TyP+KYkiUrtIlCQBOXBq/Fjp",
8+
"include_colab_link": true
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
},
14+
"language_info": {
15+
"name": "python"
16+
}
17+
},
18+
"cells": [
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {
22+
"id": "view-in-github",
23+
"colab_type": "text"
24+
},
25+
"source": [
26+
"<a href=\"https://colab.research.google.com/github/dineshreddy221/Python/blob/main/string_coding.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 1,
32+
"metadata": {
33+
"colab": {
34+
"base_uri": "https://localhost:8080/",
35+
"height": 53
36+
},
37+
"id": "XfXqXDEfHwpQ",
38+
"outputId": "a63ced56-7930-4f4e-cffa-50a7582445c1"
39+
},
40+
"outputs": [
41+
{
42+
"name": "stdout",
43+
"output_type": "stream",
44+
"text": [
45+
"input from user: string.rev.order.words\n"
46+
]
47+
},
48+
{
49+
"output_type": "execute_result",
50+
"data": {
51+
"text/plain": [
52+
"'words.order.rev.string'"
53+
],
54+
"application/vnd.google.colaboratory.intrinsic+json": {
55+
"type": "string"
56+
}
57+
},
58+
"metadata": {},
59+
"execution_count": 1
60+
}
61+
],
62+
"source": [
63+
"# Reversing the word from thier position.\n",
64+
"def rev_word_str():\n",
65+
" s = input(\"input from user: \")\n",
66+
" word = s.split(\".\")\n",
67+
" rev_sent = \".\".join(word[::-1])\n",
68+
" return rev_sent\n",
69+
"\n",
70+
"rev_word_str()"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"source": [
76+
"# Reversed word with given string using class\n",
77+
"class Solution:\n",
78+
" # Function to reverse words in a given string.\n",
79+
" def rev_word_str(self):\n",
80+
" s = input(\"Input from user: \")\n",
81+
" words = s.split(\".\")\n",
82+
" rev_sent = \".\".join(words[::-1])\n",
83+
" return rev_sent\n",
84+
"\n",
85+
"# Create an instance of the Solution class\n",
86+
"sol = Solution()\n",
87+
"\n",
88+
"# Call the rev_word_str method\n",
89+
"result = sol.rev_word_str()\n",
90+
"print(\"Reversed string:\", result)\n"
91+
],
92+
"metadata": {
93+
"colab": {
94+
"base_uri": "https://localhost:8080/"
95+
},
96+
"id": "4ys6Xl6hILN1",
97+
"outputId": "1d17328f-529e-4c76-ddcc-74eb716bd2c7"
98+
},
99+
"execution_count": 2,
100+
"outputs": [
101+
{
102+
"output_type": "stream",
103+
"name": "stdout",
104+
"text": [
105+
"Input from user: reversed.string.original\n",
106+
"Reversed string: original.string.reversed\n"
107+
]
108+
}
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"source": [
114+
" # Reverse the string with indexing\n",
115+
"s = input(\"input string: \")\n",
116+
"rev_w = s[::-1]\n",
117+
"print(\"reverse input word: \", rev_w)"
118+
],
119+
"metadata": {
120+
"colab": {
121+
"base_uri": "https://localhost:8080/"
122+
},
123+
"id": "OfTaGs1rOL1h",
124+
"outputId": "c0f7c2ad-af4a-4a88-e555-ee1c0c49cf62"
125+
},
126+
"execution_count": 3,
127+
"outputs": [
128+
{
129+
"output_type": "stream",
130+
"name": "stdout",
131+
"text": [
132+
"input string: indexing\n",
133+
"reverse input word: gnixedni\n"
134+
]
135+
}
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"source": [
141+
"string_slicing = input(\"input string from user: \")\n",
142+
"# output: Even positing of a string\n",
143+
"\n",
144+
"print(\"Even positioned string: \",\"-\".join(string_slicing[::2]))"
145+
],
146+
"metadata": {
147+
"id": "s3EG94ozPfp3",
148+
"colab": {
149+
"base_uri": "https://localhost:8080/"
150+
},
151+
"outputId": "8145d11d-97f0-4262-8bba-909f2343e964"
152+
},
153+
"execution_count": 5,
154+
"outputs": [
155+
{
156+
"output_type": "stream",
157+
"name": "stdout",
158+
"text": [
159+
"input string from user: Architecture\n",
160+
"Even positioned string: A-c-i-e-t-r\n"
161+
]
162+
}
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"source": [],
168+
"metadata": {
169+
"id": "V7gxrgLGSOM7"
170+
},
171+
"execution_count": null,
172+
"outputs": []
173+
}
174+
]
175+
}

0 commit comments

Comments
 (0)