Skip to content

Commit c32dbcd

Browse files
committed
add new file to part 1 > 05-function
1 parent 4d24f74 commit c32dbcd

File tree

2 files changed

+727
-4
lines changed

2 files changed

+727
-4
lines changed

Part1-Functional/05-FunctionParameters/05-ExtendedUnpacking.ipynb

+80-4
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,36 @@
471471
"print(f\"{s=}\") # order is not guaranteed"
472472
]
473473
},
474+
{
475+
"cell_type": "code",
476+
"execution_count": 7,
477+
"id": "e9e011e1",
478+
"metadata": {},
479+
"outputs": [
480+
{
481+
"name": "stdout",
482+
"output_type": "stream",
483+
"text": [
484+
"s={1, 2, 3, 4, 5, 6, 7, 8, 9}\n",
485+
"s={1, 2, 3, 4, 5, 6, 7, 8, 9}\n"
486+
]
487+
}
488+
],
489+
"source": [
490+
"s1 = {1, 2, 3}\n",
491+
"s2 = {3, 4, 5}\n",
492+
"s3 = {5, 6, 7}\n",
493+
"s4 = {7, 8, 9}\n",
494+
"\n",
495+
"# 1\n",
496+
"s = s1.union(s2, s3, s4) # or s = s1.union(s2).union(s3).union(s4) \n",
497+
"print(f\"{s=}\")\n",
498+
"\n",
499+
"# 2\n",
500+
"s = {*s1, *s2, *s3, *s4} # use unpacking\n",
501+
"print(f\"{s=}\")"
502+
]
503+
},
474504
{
475505
"cell_type": "markdown",
476506
"id": "21f2f26e",
@@ -698,7 +728,9 @@
698728
"cell_type": "code",
699729
"execution_count": 89,
700730
"id": "36c94426",
701-
"metadata": {},
731+
"metadata": {
732+
"scrolled": true
733+
},
702734
"outputs": [
703735
{
704736
"name": "stdout",
@@ -714,9 +746,27 @@
714746
"print(f\"{a=}, {b=}, {c=}, {d=}, {e=}\")"
715747
]
716748
},
749+
{
750+
"cell_type": "markdown",
751+
"id": "9711ca6e",
752+
"metadata": {},
753+
"source": [
754+
"#### Practice with unpacking and slicing"
755+
]
756+
},
757+
{
758+
"cell_type": "code",
759+
"execution_count": 9,
760+
"id": "8dfbc9e5",
761+
"metadata": {},
762+
"outputs": [],
763+
"source": [
764+
"l = [1, 2, 3, \"python\"]"
765+
]
766+
},
717767
{
718768
"cell_type": "code",
719-
"execution_count": 91,
769+
"execution_count": 10,
720770
"id": "24088888",
721771
"metadata": {},
722772
"outputs": [
@@ -729,10 +779,36 @@
729779
}
730780
],
731781
"source": [
732-
"a, *b, (c, *d) = [1, 2, 3, \"python\"]\n",
733-
"\n",
782+
"a, *b, (c, *d) = l\n",
783+
"print(f\"{a=}, {b=}, {c=}, {d=}\")"
784+
]
785+
},
786+
{
787+
"cell_type": "code",
788+
"execution_count": 17,
789+
"id": "bf2c4064",
790+
"metadata": {},
791+
"outputs": [
792+
{
793+
"name": "stdout",
794+
"output_type": "stream",
795+
"text": [
796+
"a=1, b=[2, 3], c='p', d=['y', 't', 'h', 'o', 'n']\n"
797+
]
798+
}
799+
],
800+
"source": [
801+
"a, b, c, d = l[0], l[1:3], l[3][0], list(l[3][1:])\n",
734802
"print(f\"{a=}, {b=}, {c=}, {d=}\")"
735803
]
804+
},
805+
{
806+
"cell_type": "code",
807+
"execution_count": null,
808+
"id": "947b9aae",
809+
"metadata": {},
810+
"outputs": [],
811+
"source": []
736812
}
737813
],
738814
"metadata": {

0 commit comments

Comments
 (0)