8000 updated! · sru0309/python_practices@a3f024a · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit a3f024a

Browse files
committed
updated!
1 parent 52b2cfd commit a3f024a

File tree

1 file changed

+325
-0
lines changed

1 file changed

+325
-0
lines changed

002-basic-string-program.ipynb

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 10,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"srushti am i hey\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"#reverse words in a give string\n",
18+
"string =\"hey i am srushti\"\n",
19+
"s = string.split()[::-1]\n",
20+
"l =[]\n",
21+
"for i in s:\n",
22+
" l.append(i)\n",
23+
"print(' '.join(l))\n"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 7,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"['srushti', 'am', 'i', 'hey']"
35+
]
36+
},
37+
"execution_count": 7,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"l"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 13,
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"you are how hii\n"
56+
]
57+
}
58+
],
59+
"source": [
60+
"#reversed \n",
61+
"def rev_sentence(sentence):\n",
62+
" words =sentence.split(' ')\n",
63+
" reversed_sentence = ' '.join(reversed(words))\n",
64+
" return reversed_sentence\n",
65+
"if __name__ == \"__main__\":\n",
66+
" input =\"hii how are you\"\n",
67+
" print(rev_sentence(input))"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 22,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"str =\"hey how are you\"\n",
77+
"split = str.split(' ')\n",
78+
"reversed_sentence =' '.join(reversed(split))"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 23,
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"data": {
88+
"text/plain": [
89+
"'you are how hey'"
90+
]
91+
},
92+
"execution_count": 23,
93+
"metadata": {},
94+
"output_type": "execute_result"
95+
}
96+
],
97+
"source": [
98+
"reversed_sentence"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 26,
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"name": "stdout",
108+
"output_type": "stream",
109+
"text": [
110+
"u o y e r a w o h\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"str =\"how are you\"\n",
116+
"rev = ' '.join(reversed(str)) #space \n",
117+
"print(rev)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 27,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"uoy era woh\n"
130+
]
131+
}
132+
],
133+
"source": [
134+
"str = \"how are you\"\n",
135+
"rev = ''.join(reversed(str)) #without space\n",
136+
"print(rev)"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": 28,
142+
"metadata": {},
143+
"outputs": [],
144+
"source": [
145+
"#replacing the characters from the string\n",
146+
"str = \"i am srushti\"\n",
147+
"replace = str.replace(\"a\",'')"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 30,
153+
"metadata": {},
154+
"outputs": [
155+
{
156+
"data": {
157+
"text/plain": [
158+
"'i m srushti'"
159+
]
160+
},
161+
"execution_count": 30,
162+
"metadata": {},
163+
"output_type": "execute_result"
164+
}
165+
],
166+
"source": [
167+
"replace"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 32,
173+
"metadata": {},
174+
"outputs": [],
175+
"source": [
176+
"str =\"i am srushti\"\n",
177+
"str2 = str.replace(\"s\",'',1)"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 34,
183+
"metadata": {},
184+
"outputs": [
185+
{
186+
"data": {
187+
"text/plain": [
188+
"'i am rushti'"
189+
]
190+
},
191+
"execution_count": 34,
192+
"metadata": {},
193+
"output_type": "execute_result"
194+
}
195+
],
196+
"source": [
197+
"str2"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 38,
203+
"metadata": {},
204+
"outputs": [],
205+
"source": [
206+
"str2 = str.replace(\"s\",\"n\",2)"
207+
]
208+
},
209+
{
210+
"cell_type": "code",
211+
"execution_count": 40,
212+
"metadata": {},
213+
"outputs": [
214+
{
215+
"data": {
216+
"text/plain": [
217+
"'i am nrunhti'"
218+
]
219+
},
220+
"execution_count": 40,
221+
"metadata": {},
222+
"output_type": "execute_result"
223+
}
224+
],
225+
"source": [
226+
"str2"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": 53,
232+
"metadata": {},
233+
"outputs": [
234+
{
235+
"name": "stdout",
236+
"output_type": "stream",
237+
"text": [
238+
"this\n",
239+
"is\n",
240+
"python\n",
241+
"language\n"
242+
]
243+
}
244+
],
245+
"source": [
246+
"#program to print even length words in a string\n",
247+
"n = \"this is a python language\"\n",
248+
"s= n.split(\" \")\n",
249+
"for i in s:\n",
250+
" if len(i)%2==0:\n",
251+
" print(i)"
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": 51,
257+
"metadata": {},
258+
"outputs": [
259+
{
260+
"data": {
261+
"text/plain": [
262+
"['this', 'is', 'a', 'python', 'language']"
263+
]
264+
},
265+
"execution_count": 51,
266+
"metadata": {},
267+
"output_type": "execute_result"
268+
}
269+
],
270+
"source": [
271+
"s"
272+
]
273+
},
274+
{
275+
"cell_type": "code",
276+
"execution_count": 55,
277+
"metadata": {},
278+
"outputs": [
279+
{
280+
"name": "stdout",
281+
"output_type": "stream",
282+
"text": [
283+
"this\n",
284+
"language\n"
285+
]
286+
}
287+
],
288+
"source": [
289+
"n = \"this is a python language\"\n",
290+
"s= n.split(\" \")\n",
291+
"for i in s:\n",
292+
" if len(i)%4==0:\n",
293+
" print(i)\n",
294+
" "
295+
]
296+
}
297+
],
298+
"metadata": {
299+
"kernelspec": {
300+
"display_name": "Python 3.9.12 ('base')",
301+
"language": "python",
302+
"name": "python3"
303+
},
304+
"language_info": {
305+
"codemirror_mode": {
306+
"name": "ipython",
307+
"version": 3
308+
},
309+
"file_extension": ".py",
310+
"mimetype": "text/x-python",
311+
"name": "python",
312+
"nbconvert_exporter": "python",
313+
"pygments_lexer": "ipython3",
314+
"version": "3.9.12"
315+
},
316+
"orig_nbformat": 4,
317+
"vscode": {
318+
"interpreter": {
319+
"hash": "daee99e6893c0f9b4fa2cee7c11289a4ac1788238c3c1d2caa83921531d37465"
320+
}
321+
}
322+
},
323+
"nbformat": 4,
324+
"nbformat_minor": 2
325+
}

0 commit comments

Comments
 (0)
0