Skip to content

Commit d1bf05b

Browse files
committed
fix error example and add some examples
1 parent caac536 commit d1bf05b

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

ipythons/Strain_your_brain.ipynb

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,11 @@
757757
"metadata": {},
758758
"outputs": [],
759759
"source": [
760+
"ordered_dict = OrderedDictWithHash(ordered_dict)\n",
761+
"another_ordered_dict = OrderedDictWithHash(another_ordered_dict)\n",
760762
"another_set = set()\n",
761763
"another_set.add(ordered_dict)\n",
762-
"another_ordered_dict in another_set\n",
763-
"=> False"
764+
"another_ordered_dict in another_set"
764765
]
765766
},
766767
{
@@ -866,6 +867,102 @@
866867
" print(f\"Zero division error occurred: {e}\")"
867868
]
868869
},
870+
{
871+
"cell_type": "markdown",
872+
"metadata": {},
873+
"source": [
874+
"### For what?"
875+
]
876+
},
877+
{
878+
"cell_type": "code",
879+
"execution_count": null,
880+
"metadata": {},
881+
"outputs": [],
882+
"source": [
883+
"some_string = \"wtf\"\n",
884+
"some_dict = {}\n",
885+
"for i, some_dict[i] in enumerate(some_string):\n",
886+
" i = 10"
887+
]
888+
},
889+
{
890+
"cell_type": "code",
891+
"execution_count": null,
892+
"metadata": {},
893+
"outputs": [],
894+
"source": [
895+
"some_dict"
896+
]
897+
},
898+
{
899+
"cell_type": "code",
900+
"execution_count": null,
901+
"metadata": {},
902+
"outputs": [],
903+
"source": [
904+
"i, some_dict[i] = (0, 'w')\n",
905+
"i, some_dict[i] = (1, 't')\n",
906+
"i, some_dict[i] = (2, 'f')\n",
907+
"some_dict"
908+
]
909+
},
910+
{
911+
"cell_type": "markdown",
912+
"metadata": {},
913+
"source": [
914+
"### Evaluation time discrepancy"
915+
]
916+
},
917+
{
918+
"cell_type": "code",
919+
"execution_count": null,
920+
"metadata": {},
921+
"outputs": [],
922+
"source": [
923+
"array = [1, 8, 15]\n",
924+
"# A typical generator expression\n",
925+
"gen = (x for x in array if array.count(x) > 0)\n",
926+
"array = [2, 8, 22]\n",
927+
"print(list(gen))\n",
928+
"print(type(gen))"
929+
]
930+
},
931+
{
932+
"cell_type": "code",
933+
"execution_count": null,
934+
"metadata": {},
935+
"outputs": [],
936+
"source": [
937+
"array_1 = [1,2,3,4]\n",
938+
"gen_1 = (x for x in array_1)\n",
939+
"array_1 = [1,2,3,4,5]\n",
940+
"\n",
941+
"array_2 = [1,2,3,4]\n",
942+
"gen_2 = (x for x in array_2)\n",
943+
"array_2[:] = [1,2,3,4,5]\n",
944+
"\n",
945+
"print(list(gen_1))\n",
946+
"\n",
947+
"print(list(gen_2))"
948+
]
949+
},
950+
{
951+
"cell_type": "code",
952+
"execution_count": null,
953+
"metadata": {},
954+
"outputs": [],
955+
"source": [
956+
"array_3 = [1, 2, 3]\n",
957+
"array_4 = [10, 20, 30]\n",
958+
"gen = (i + j for i in array_3 for j in array_4)\n",
959+
"\n",
960+
"array_3 = [4, 5, 6]\n",
961+
"array_4 = [400, 500, 600]\n",
962+
"\n",
963+
"print(list(gen))"
964+
]
965+
},
869966
{
870967
"cell_type": "code",
871968
"execution_count": null,

0 commit comments

Comments
 (0)