Skip to content

Commit

Permalink
day 3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
atifiu committed Dec 31, 2023
1 parent 6ffec4e commit c72e4f3
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 7 deletions.
86 changes: 86 additions & 0 deletions python_concepts/enumerate.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Enumerate use cases\n",
"Enumerate is used to provide an index/counter with iterable"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 0\n",
"2 2\n",
"3 4\n",
"4 6\n",
"5 8\n",
"6 10\n",
"7 12\n",
"8 14\n",
"9 16\n",
"10 18\n",
"11 20\n"
]
}
],
"source": [
"list1 = [i*2 for i in range(11)]\n",
"for count, value in enumerate(list1, start = 1):\n",
" print(count, value)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 a d g\n",
"2 b e h\n",
"3 c f i\n"
]
}
],
"source": [
"## Combining enumerate with zip\n",
"first = [\"a\", \"b\", \"c\"]\n",
"second = [\"d\", \"e\", \"f\"]\n",
"third = [\"g\", \"h\", \"i\"]\n",
"for count, (one, two, three) in enumerate(zip(first, second, third), start = 1):\n",
" print(count, one, two, three)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dashboard",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
73 changes: 66 additions & 7 deletions python_daily_exercies/day3_31_12_2023.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,83 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'A': 100, 'B': 200, 'C': 300}\n"
]
}
},
"outputs": [],
],
"source": [
"dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
"dict2 = {k.upper():v*100 for (k,v) in dict1.items()}\n",
"# Here dictionary.items returns key value pair\n",
"print(dict2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert code into set comprehension\n",
"a = set()\n",
"for n in range(21,40):\n",
" if n%2 == 0:\n",
" a.add(n)\n",
"print(a)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'set'>\n"
]
},
{
"data": {
"text/plain": [
"{22, 24, 26, 28, 30, 32, 34, 36, 38}"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = {n for n in range(21,40) if n%2 == 0 }\n",
"print(type(a))\n",
"a\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dashboard",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit c72e4f3

Please sign in to comment.