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

Skip to content

Commit 43d0926

Browse files
committed
updated!
1 parent a3f024a commit 43d0926

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

002-basic-string-program.ipynb

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"- reverse words in a give string"
8+
]
9+
},
310
{
411
"cell_type": "code",
512
"execution_count": 10,
@@ -136,6 +143,13 @@
136143
"print(rev)"
137144
]
138145
},
146+
{
147+
"cell_type": "markdown",
148+
"metadata": {},
149+
"source": [
150+
"- replacing the characters from the string"
151+
]
152+
},
139153
{
140154
"cell_type": "code",
141155
"execution_count": 28,
@@ -226,6 +240,13 @@
226240
"str2"
227241
]
228242
},
243+
{
244+
"cell_type": "markdown",
245+
"metadata": {},
246+
"source": [
247+
"- program to print even length words in a string"
248+
]
249+
},
229250
{
230251
"cell_type": "code",
231252
"execution_count": 53,
@@ -293,6 +314,146 @@
293314
" print(i)\n",
294315
" "
295316
]
317+
},
318+
{
319+
"cell_type": "code",
320+
"execution_count": 3,
321+
"metadata": {},
322+
"outputs": [
323+
{
324+
"name": "stdout",
325+
"output_type": "stream",
326+
"text": [
327+
"python\n"
328+
]
329+
}
330+
],
331+
"source": [
332+
"n = \"This is a python launguage\"\n",
333+
"s = n.split(\" \")\n",
334+
"for i in s:\n",
335+
" if len(i)%6==0:\n",
336+
" print(i)"
337+
]
338+
},
339+
{
340+
"cell_type": "code",
341+
"execution_count": 8,
342+
"metadata": {},
343+
"outputs": [],
344+
"source": [
345+
"def printwords(s):\n",
346+
" s =\"this is easy language\"\n",
347+
" s=s.split(' ')\n",
348+
" for i in s:\n",
349+
" if len(i)%2==0:\n",
350+
" print(i)\n"
351+
]
352+
},
353+
{
354+
"cell_type": "code",
355+
"execution_count": 10,
356+
"metadata": {},
357+
"outputs": [
358+
{
359+
"name": "stdout",
360+
"output_type": "stream",
361+
"text": [
362+
"this\n",
363+
"is\n",
364+
"easy\n",
365+
"language\n",
366+
"None\n"
367+
]
368+
}
369+
],
370+
"source": [
371+
"print(printwords(s))"
372+
]
373+
},
374+
{
375+
"cell_type": "code",
376+
"execution_count": 15,
377+
"metadata": {},
378+
"outputs": [
379+
{
380+
"ename": "TypeError",
381+
"evalue": "filter expected 2 arguments, got 1",
382+
"output_type": "error",
383+
"traceback": [
384+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
385+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
386+
"\u001b[1;32md:\\Python\\python_practice\\002-basic-string-program.ipynb Cell 23\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/002-basic-string-program.ipynb#X32sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m n \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mthis is easy language\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/002-basic-string-program.ipynb#X32sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m s\u001b[39m=\u001b[39mn\u001b[39m.\u001b[39msplit(\u001b[39m'\u001b[39m\u001b[39m \u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m----> <a href='vscode-notebook-cell:/d%3A/Python/python_practice/002-basic-string-program.ipynb#X32sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m l\u001b[39m=\u001b[39m\u001b[39mlist\u001b[39m(\u001b[39mfilter\u001b[39;49m(\u001b[39mlambda\u001b[39;49;00m x : (\u001b[39mlen\u001b[39;49m(x)\u001b[39m%\u001b[39;49m\u001b[39m2\u001b[39;49m\u001b[39m==\u001b[39;49m\u001b[39m0\u001b[39;49m)\u001b[39m.\u001b[39;49ms))\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/002-basic-string-program.ipynb#X32sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m \u001b[39mprint\u001b[39m(s)\n",
387+
"\u001b[1;31mTypeError\u001b[0m: filter expected 2 arguments, got 1"
388+
]
389+
}
390+
],
391+
"source": [
392+
"n = \"this is easy language\"\n",
393+
"s=n.split(' ')\n",
394+
"l=list(filter(lambda x : (len(x)%2==0).s))\n",
395+
"print(s)\n"
396+
]
397+
},
398+
{
399+
"cell_type": "code",
400+
"execution_count": 16,
401+
"metadata": {},
402+
"outputs": [
403+
{
404+
"name": "stdout",
405+
"output_type": "stream",
406+
"text": [
407+
"['this', 'is', 'easy', 'language']\n"
408+
]
409+
}
410+
],
411+
"source": [
412+
"n=\"this is easy language\"\n",
413+
"s=n.split(' ')\n",
414+
"print([x for x in s if len(x)%2==0])"
415+
]
416+
},
417+
{
418+
"cell_type": "markdown",
419+
"metadata": {},
420+
"source": [
421+
"- using slicing and upper()and split()"
422+
]
423+
},
424+
{
425+
"cell_type": "code",
426+
"execution_count": 25,
427+
"metadata": {},
428+
"outputs": [
429+
{
430+
"name": "stdout",
431+
"output_type": "stream",
432+
"text": [
433+
"string before : this is easy language\n",
434+
"string after: ThiS IS EasY LanguagE\n"
435+
]
436+
}
437+
],
438+
"source": [
439+
"#using slicing and upper() and split()\n",
440+
"n = \"this is easy language\"\n",
441+
"print(\"string before :\",n)\n",
442+
"a =n.split(' ')\n",
443+
"res =[]\n",
444+
"for i in a:\n",
445+
" x=i[0].upper()+i[1:-1]+i[-1].upper()\n",
446+
" res.append(x)\n",
447+
"res=\" \".join(res)\n",
448+
"print(\"string after:\",res) "
449+
]
450+
},
451+
{
452+
"cell_type": "code",
453+
"execution_count": null,
454+
"metadata": {},
455+
"outputs": [],
456+
"source": []
296457
}
297458
],
298459
"metadata": {

0 commit comments

Comments
 (0)
0