Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb6a2a2

Browse files
Add files via upload
1 parent dece418 commit fb6a2a2

21 files changed

+7146
-0
lines changed

‎Python_Coding_Test1.ipynb‎

Lines changed: 540 additions & 0 deletions
Large diffs are not rendered by default.

‎Python_Daily_Challenge1.ipynb‎

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "4221f9eb-836e-45e8-86ed-b5399fb7f556",
6+
"metadata": {
7+
"id": "4221f9eb-836e-45e8-86ed-b5399fb7f556"
8+
},
9+
"source": [
10+
"# Daily Challenge Questions"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "e71d7e35-2485-40c2-9e12-18b4d04dd701",
16+
"metadata": {
17+
"id": "e71d7e35-2485-40c2-9e12-18b4d04dd701"
18+
},
19+
"source": [
20+
"# Question 1:\n",
21+
"\n",
22+
"Given the nested list **data** = [[['a', 'b', 'c'], ['d', 'e', 'f']], [['g', 'h', 'i'], ['j', 'k', 'l']]], using list comprehension, **create a new list containing all vowels from data.**\n",
23+
"\n",
24+
"**Output:**\n",
25+
"\n",
26+
"For the given data, the output list should be **['a', 'e', 'i'].**"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"id": "72807312-6d82-4b89-89b8-3f5ebf4fc340",
33+
"metadata": {
34+
"colab": {
35+
"base_uri": "https://localhost:8080/"
36+
},
37+
"id": "72807312-6d82-4b89-89b8-3f5ebf4fc340",
38+
"outputId": "ea13e8bc-eb07-4311-d0ea-59371001142e"
39+
},
40+
"outputs": [
41+
{
42+
"output_type": "stream",
43+
"name": "stdout",
44+
"text": [
45+
"Vowels present in given data are: ['a', 'e', 'i']\n"
46+
]
47+
}
48+
],
49+
"source": [
50+
"data = [[['a', 'b', 'c'], ['d', 'e', 'f']], [['g', 'h', 'i'], ['j', 'k', 'l']]]\n",
51+
"\n",
52+
"# looping through sub-lists using list comprehension\n",
53+
"# sub-list in list\n",
54+
"# sub-sub-list in sub-list\n",
55+
"# sub-sub-sub-list in sub-sub-list\n",
56+
"\n",
57+
"vowel_list = [x for ele_list in data for coll_list in ele_list for x in coll_list if x in ['a', 'e', 'i','o','u']]\n",
58+
"\n",
59+
"print(\"Vowels present in given data are: \", vowel_list)"
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"id": "1bf9e7f4-885e-4f16-8e73-1edc83028db6",
65+
"metadata": {
66+
"id": "1bf9e7f4-885e-4f16-8e73-1edc83028db6"
67+
},
68+
"source": [
69+
" # Question 2:\n",
70+
"\n",
71+
"\n",
72+
"Given the nested tuple **info** = ((('Alice', 25), ('Bob', 30)), (('Charlie', 22), ('David', 28))), using tuple unpacking and list comprehension, create a new list containing the **ages of all individuals whose names start with 'D'**.\n",
73+
"\n",
74+
"**Output:**\n",
75+
"\n",
76+
"For the given info, the output list should be [28,26,32,27]."
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"id": "1feeba73-778c-49dd-8c9c-580d0dc9b364",
83+
"metadata": {
84+
"id": "1feeba73-778c-49dd-8c9c-580d0dc9b364",
85+
"colab": {
86+
"base_uri": "https://localhost:8080/"
87+
},
88+
"outputId": "d8b59321-938c-4c8b-9f9c-00cae5f5d464"
89+
},
90+
"outputs": [
91+
{
92+
"output_type": "stream",
93+
"name": "stdout",
94+
"text": [
95+
"[28, 26, 32, 27]\n"
96+
]
97+
}
98+
],
99+
"source": [
100+
"info = (\n",
101+
" (('Alice', 25), ('Bob', 30)),\n",
102+
" (('Charlie', 22), ('David', 28)),\n",
103+
" (('Diana', 26), ('Derek', 32)),\n",
104+
" (('Daniel', 27), ('Emily', 29))\n",
105+
")\n",
106+
"\n",
107+
"# looping through sub-tuples using list comprehension\n",
108+
"# sub-tuple in tuple\n",
109+
"# (name,age) in sub-tuple\n",
110+
"# if name.startswith('D') --> append age into list\n",
111+
"age_list_whose_name_startswith_letter_D = [age for x in info for (name,age) in x if name.startswith(\"D\")]\n",
112+
"print(age_list_whose_name_startswith_letter_D)"
113+
]
114+
},
115+
{
116+
"cell_type": "markdown",
117+
"id": "07ac759c-f8ac-4779-ba86-0a0a2cea5a6e",
118+
"metadata": {
119+
"id": "07ac759c-f8ac-4779-ba86-0a0a2cea5a6e"
120+
},
121+
"source": [
122+
"# Question 3\n",
123+
"\n",
124+
"Given the nested dictionary **data** = {'A': {'x': [1, 2, 3]}, 'B': {'y': [4, 5, 6]}}, using dictionary comprehension, create a new dictionary where each key is from the original dictionary and each value is the sum of its associated list values.\n",
125+
"\n",
126+
"**Output:**\n",
127+
"\n",
128+
"For the given data, the output dictionary should be {'A': 6, 'B': 15}.\n",
129+
"\n"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "d693d5d8-66b4-4b97-bab8-223ab01f6e24",
136+
"metadata": {
137+
"id": "d693d5d8-66b4-4b97-bab8-223ab01f6e24",
138+
"colab": {
139+
"base_uri": "https://localhost:8080/"
140+
},
141+
"outputId": "099e7e91-1300-490c-d48e-2208ff5826fa"
142+
},
143+
"outputs": [
144+
{
145+
"output_type": "stream",
146+
"name": "stdout",
147+
"text": [
148+
"{'A': 6, 'B': 15}\n"
149+
]
150+
}
151+
],
152+
"source": [
153+
"data = {'A': {'x': [1, 2, 3]}, 'B': {'y': [4, 5, 6]}}\n",
154+
"\n",
155+
"# looping through sub-values using dictionary comprehension\n",
156+
"# (key,value)pair in dict.items()\n",
157+
"# val_list in value.values()\n",
158+
"# sum(val_list)\n",
159+
"dict_new = {m: sum(i) for m,n in data.items() for i in n.values()}\n",
160+
"print(dict_new)"
161+
]
162+
}
163+
],
164+
"metadata": {
165+
"kernelspec": {
166+
"display_name": "Python 3 (ipykernel)",
167+
"language": "python",
168+
"name": "python3"
169+
},
170+
"language_info": {
171+
"codemirror_mode": {
172+
"name": "ipython",
173+
"version": 3
174+
},
175+
"file_extension": ".py",
176+
"mimetype": "text/x-python",
177+
"name": "python",
178+
"nbconvert_exporter": "python",
179+
"pygments_lexer": "ipython3",
180+
"version": "3.11.8"
181+
},
182+
"colab": {
183+
"provenance": []
184+
}
185+
},
186+
"nbformat": 4,
187+
"nbformat_minor": 5
188+
}

‎Python_Daily_Challenge2.ipynb‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "4221f9eb-836e-45e8-86ed-b5399fb7f556",
6+
"metadata": {
7+
"id": "4221f9eb-836e-45e8-86ed-b5399fb7f556"
8+
},
9+
"source": [
10+
"# Daily Challenge Questions July 16"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "e71d7e35-2485-40c2-9e12-18b4d04dd701",
16+
"metadata": {
17+
"id": "e71d7e35-2485-40c2-9e12-18b4d04dd701"
18+
},
19+
"source": [
20+
"# Question 1:\n",
21+
"\n",
22+
"Given the nested tuple info = ((('Emma', 26), ('Frank', 32)), (('Grace', 29), ('Henry', 27)), (('Ivy', 30), ('Jack', 25)), (('Kate', 28), ('Leo', 31))).\n",
23+
"\n",
24+
"Using tuple unpacking and list comprehension, create a new list containing the **ages of all individuals whose names end with 'y'.**"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "72807312-6d82-4b89-89b8-3f5ebf4fc340",
31+
"metadata": {
32+
"colab": {
33+
"base_uri": "https://localhost:8080/"
34+
},
35+
"id": "72807312-6d82-4b89-89b8-3f5ebf4fc340",
36+
"outputId": "8ec93012-22fb-4846-f644-75ce2b5e531c"
37+
},
38+
"outputs": [
39+
{
40+
"output_type": "stream",
41+
"name": "stdout",
42+
"text": [
43+
"[27, 30]\n"
44+
]
45+
}
46+
],
47+
"source": [
48+
"info = ((('Emma', 26), ('Frank', 32)), (('Grace', 29), ('Henry', 27)), (('Ivy', 30), ('Jack', 25)), (('Kate', 28), ('Leo', 31)))\n",
49+
"\n",
50+
"age_of_individual_whose_name_ends_with_y = [age for pair in info for (name,age) in pair if name.endswith('y')]\n",
51+
"\n",
52+
"print(age_of_individual_whose_name_ends_with_y)"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"id": "1bf9e7f4-885e-4f16-8e73-1edc83028db6",
58+
"metadata": {
59+
"id": "1bf9e7f4-885e-4f16-8e73-1edc83028db6"
60+
},
61+
"source": [
62+
" # Question 2:\n",
63+
"\n",
64+
"Given the nested list data = [[['a', 'b', 'c'], ['d', 'e', 'f']], [['g', 'h', 'i'], ['j', 'k', 'l']]].\n",
65+
"\n",
66+
"Using list comprehension, create a **new list containing all characters from data that are not vowels ('a', 'e', 'i', 'o', 'u').**"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"id": "1feeba73-778c-49dd-8c9c-580d0dc9b364",
73+
"metadata": {
74+
"colab": {
75+
"base_uri": "https://localhost:8080/"
76+
},
77+
"id": "1feeba73-778c-49dd-8c9c-580d0dc9b364",
78+
"outputId": "f6b9f36f-fac0-4f3b-cd7f-a5dbddc4f5e3"
79+
},
80+
"outputs": [
81+
{
82+
"output_type": "stream",
83+
"name": "stdout",
84+
"text": [
85+
"['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l']\n"
86+
]
87+
}
88+
],
89+
"source": [
90+
"data = [[['a', 'b', 'c'], ['d', 'e', 'f']], [['g', 'h', 'i'], ['j', 'k', 'l']]]\n",
91+
"\n",
92+
"consonant_in_data = [x for collections in data for items in collections for x in items if x not in ['a', 'e', 'i', 'o', 'u']]\n",
93+
"\n",
94+
"print(consonant_in_data)"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"id": "07ac759c-f8ac-4779-ba86-0a0a2cea5a6e",
100+
"metadata": {
101+
"id": "07ac759c-f8ac-4779-ba86-0a0a2cea5a6e"
102+
},
103+
"source": [
104+
"# Question 3\n",
105+
"\n",
106+
"Given the nested dictionary **data** = {'A': {'x': [1, 2, 3]}, 'B': {'y': [4, 5, 6]}}, using dictionary comprehension, create a new dictionary where each key is from the original dictionary and each value is the sum of its associated list values.\n",
107+
"\n",
108+
"**Output:**\n",
109+
"\n",
110+
"For the given data, the output dictionary should be {'A': 6, 'B': 15}.\n",
111+
"\n"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"id": "d693d5d8-66b4-4b97-bab8-223ab01f6e24",
118+
"metadata": {
119+
"colab": {
120+
"base_uri": "https://localhost:8080/"
121+
},
122+
"id": "d693d5d8-66b4-4b97-bab8-223ab01f6e24",
123+
"outputId": "ed0f542b-ec8d-47a9-d903-167f94b2ad1e"
124+
},
125+
"outputs": [
126+
{
127+
"output_type": "stream",
128+
"name": "stdout",
129+
"text": [
130+
"{'A': 6, 'B': 15}\n"
131+
]
132+
}
133+
],
134+
"source": [
135+
"data = {'A': {'x': [1, 2, 3]}, 'B': {'y': [4, 5, 6]}}\n",
136+
"\n",
137+
"new_dict_data = {m : sum(i) for (m,n) in data.items() for i in n.values()}\n",
138+
"\n",
139+
"print(new_dict_data)"
140+
]
141+
}
142+
],
143+
"metadata": {
144+
"kernelspec": {
145+
"display_name": "Python 3 (ipykernel)",
146+
"language": "python",
147+
"name": "python3"
148+
},
149+
"language_info": {
150+
"codemirror_mode": {
151+
"name": "ipython",
152+
"version": 3
153+
},
154+
"file_extension": ".py",
155+
"mimetype": "text/x-python",
156+
"name": "python",
157+
"nbconvert_exporter": "python",
158+
"pygments_lexer": "ipython3",
159+
"version": "3.11.8"
160+
},
161+
"colab": {
162+
"provenance": []
163+
}
164+
},
165+
"nbformat": 4,
166+
"nbformat_minor": 5
167+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /