Skip to content

Commit abf30db

Browse files
committed
practice
1 parent abdc618 commit abf30db

File tree

2 files changed

+264
-0
lines changed

2 files changed

+264
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "04d8c7b0",
6+
"metadata": {},
7+
"source": [
8+
"## string length"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 2,
14+
"id": "6bb6fb9e",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"enter a string: welcome to tops\n",
22+
"15\n"
23+
]
24+
}
25+
],
26+
"source": [
27+
"s = input('enter a string: ')\n",
28+
"c = 0\n",
29+
"for i in s:\n",
30+
" c += 1\n",
31+
"else:\n",
32+
" print(c)"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "7966e262",
38+
"metadata": {},
39+
"source": [
40+
"### substring in a string count"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 3,
46+
"id": "afa939d9",
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
"2\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"string = 'welcome to tops'\n",
59+
"substring = 'to'\n",
60+
"\n",
61+
"c = string.count(substring)\n",
62+
"\n",
63+
"print(c)"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"id": "4025f67d",
69+
"metadata": {},
70+
"source": [
71+
"### count the occurrences of each word in a given sentence"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 4,
77+
"id": "db1d297f",
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"name": "stdout",
82+
"output_type": "stream",
83+
"text": [
84+
"enter your string: welcome to tops, welcome to india\n",
85+
"{'welcome': 2, 'to': 2, 'tops,': 1, 'india': 1}\n"
86+
]
87+
}
88+
],
89+
"source": [
90+
"s = input('enter your string: ') \n",
91+
"s = s.split()\n",
92+
"d = {}\n",
93+
"\n",
94+
"for i in s:\n",
95+
" if i in d:\n",
96+
" d[i] += 1\n",
97+
" else:\n",
98+
" d[i] = 1\n",
99+
"print(d)"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"id": "be34f3ed",
106+
"metadata": {},
107+
"outputs": [],
108+
"source": []
109+
}
110+
],
111+
"metadata": {
112+
"kernelspec": {
113+
"display_name": "Python 3 (ipykernel)",
114+
"language": "python",
115+
"name": "python3"
116+
},
117+
"language_info": {
118+
"codemirror_mode": {
119+
"name": "ipython",
120+
"version": 3
121+
},
122+
"file_extension": ".py",
123+
"mimetype": "text/x-python",
124+
"name": "python",
125+
"nbconvert_exporter": "python",
126+
"pygments_lexer": "ipython3",
127+
"version": "3.9.12"
128+
}
129+
},
130+
"nbformat": 4,
131+
"nbformat_minor": 5
132+
}

python_find_length_string.ipynb

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "04d8c7b0",
6+
"metadata": {},
7+
"source": [
8+
"## string length"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 2,
14+
"id": "6bb6fb9e",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"enter a string: welcome to tops\n",
22+
"15\n"
23+
]
24+
}
25+
],
26+
"source": [
27+
"s = input('enter a string: ')\n",
28+
"c = 0\n",
29+
"for i in s:\n",
30+
" c += 1\n",
31+
"else:\n",
32+
" print(c)"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "7966e262",
38+
"metadata": {},
39+
"source": [
40+
"### substring in a string count"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 3,
46+
"id": "afa939d9",
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
"2\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"string = 'welcome to tops'\n",
59+
"substring = 'to'\n",
60+
"\n",
61+
"c = string.count(substring)\n",
62+
"\n",
63+
"print(c)"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"id": "4025f67d",
69+
"metadata": {},
70+
"source": [
71+
"### count the occurrences of each word in a given sentence"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 4,
77+
"id": "db1d297f",
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"name": "stdout",
82+
"output_type": "stream",
83+
"text": [
84+
"enter your string: welcome to tops, welcome to india\n",
85+
"{'welcome': 2, 'to': 2, 'tops,': 1, 'india': 1}\n"
86+
]
87+
}
88+
],
89+
"source": [
90+
"s = input('enter your string: ') \n",
91+
"s = s.split()\n",
92+
"d = {}\n",
93+
"\n",
94+
"for i in s:\n",
95+
" if i in d:\n",
96+
" d[i] += 1\n",
97+
" else:\n",
98+
" d[i] = 1\n",
99+
"print(d)"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"id": "be34f3ed",
106+
"metadata": {},
107+
"outputs": [],
108+
"source": []
109+
}
110+
],
111+
"metadata": {
112+
"kernelspec": {
113+
"display_name": "Python 3 (ipykernel)",
114+
"language": "python",
115+
"name": "python3"
116+
},
117+
"language_info": {
118+
"codemirror_mode": {
119+
"name": "ipython",
120+
"version": 3
121+
},
122+
"file_extension": ".py",
123+
"mimetype": "text/x-python",
124+
"name": "python",
125+
"nbconvert_exporter": "python",
126+
"pygments_lexer": "ipython3",
127+
"version": "3.9.12"
128+
}
129+
},
130+
"nbformat": 4,
131+
"nbformat_minor": 5
132+
}

0 commit comments

Comments
 (0)