Skip to content

Commit 101fc3e

Browse files
Day73
1 parent 00beac8 commit 101fc3e

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# **Python Programming Questions**"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"### `Problem 1: Running Sum on list, Write a program to print a list after performing running sum on it`\n",
15+
"\n",
16+
"i.e:\n",
17+
"\n",
18+
"`Input:`\n",
19+
"\n",
20+
"list1 = [1,2,3,4,5,6]\n",
21+
"\n",
22+
"`Output:`\n",
23+
"\n",
24+
"[1,3,6,10,15,21]\n"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"[1, 3, 6, 10, 15, 21]\n"
37+
]
38+
}
39+
],
40+
"source": [
41+
"list1 = [1, 2, 3, 4, 5, 6]\n",
42+
"\n",
43+
"# Perform running sum\n",
44+
"for i in range(1, len(list1)):\n",
45+
" list1[i] += list1[i - 1]\n",
46+
"\n",
47+
"print(list1)"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"### `Problem 2: Find list of common unique items from two list. and show in increasing order`\n",
55+
"\n",
56+
"`Input`\n",
57+
"\n",
58+
"\n",
59+
"num1 = [23,45,67,78,89,34]\n",
60+
"num2 = [34,89,55,56,39,67]\n",
61+
"\n",
62+
"\n",
63+
"`Output:`\n",
64+
"\n",
65+
"[34, 67, 89]\n",
66+
"\n"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 2,
72+
"metadata": {},
73+
"outputs": [
74+
{
75+
"name": "stdout",
76+
"output_type": "stream",
77+
"text": [
78+
"[34, 67, 89]\n"
79+
]
80+
}
81+
],
82+
"source": [
83+
"num1 = [23, 45, 67, 78, 89, 34]\n",
84+
"num2 = [34, 89, 55, 56, 39, 67]\n",
85+
"\n",
86+
"# Find common unique items\n",
87+
"common_items = list(set(num1) & set(num2))\n",
88+
"\n",
89+
"# Sort the common items in increasing order\n",
90+
"common_items.sort()\n",
91+
"\n",
92+
"print(common_items)\n"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"### `Problem 3: Write a program that can perform union operation on 2 lists`\n",
100+
"\n",
101+
"**Example:**\n",
102+
"\n",
103+
"Input:\n",
104+
"\n",
105+
"```bash\n",
106+
"[1,2,3,4,5,1]\n",
107+
"[2,3,5,7,8]\n",
108+
"```\n",
109+
"\n",
110+
"Output:\n",
111+
"```bash\n",
112+
"[1,2,3,4,5,7,8]\n",
113+
"```"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 3,
119+
"metadata": {},
120+
"outputs": [
121+
{
122+
"name": "stdout",
123+
"output_type": "stream",
124+
"text": [
125+
"[1, 2, 3, 4, 5, 7, 8]\n"
126+
]
127+
}
128+
],
129+
"source": [
130+
"list1 = [1, 2, 3, 4, 5, 1]\n",
131+
"list2 = [2, 3, 5, 7, 8]\n",
132+
"\n",
133+
"# Perform union operation\n",
134+
"union_result = list(set(list1) | set(list2))\n",
135+
"\n",
136+
"print(union_result)"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"metadata": {},
142+
"source": [
143+
"### `Problem 4: Write a program that can find the max number of each row of a matrix`\n",
144+
"\n",
145+
"**Example:**\n",
146+
"\n",
147+
"Input:\n",
148+
"\n",
149+
"```bash\n",
150+
"[[1,2,3],[4,5,6],[7,8,9]]\n",
151+
"```\n",
152+
"\n",
153+
"Output:\n",
154+
"```bash\n",
155+
"[3,6,9]\n",
156+
"```"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": 4,
162+
"metadata": {},
163+
"outputs": [
164+
{
165+
"name": "stdout",
166+
"output_type": "stream",
167+
"text": [
168+
"[3, 6, 9]\n"
169+
]
170+
}
171+
],
172+
"source": [
173+
"matrix = [\n",
174+
" [1, 2, 3],\n",
175+
" [4, 5, 6],\n",
176+
" [7, 8, 9]\n",
177+
"]\n",
178+
"\n",
179+
"# Find the max number of each row\n",
180+
"max_numbers = [max(row) for row in matrix]\n",
181+
"\n",
182+
"print(max_numbers)\n"
183+
]
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "base",
189+
"language": "python",
190+
"name": "python3"
191+
},
192+
"language_info": {
193+
"codemirror_mode": {
194+
"name": "ipython",
195+
"version": 3
196+
},
197+
"file_extension": ".py",
198+
"mimetype": "text/x-python",
199+
"name": "python",
200+
"nbconvert_exporter": "python",
201+
"pygments_lexer": "ipython3",
202+
"version": "3.9.18"
203+
}
204+
},
205+
"nbformat": 4,
206+
"nbformat_minor": 2
207+
}

0 commit comments

Comments
 (0)