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

Appearance settings

Commit a334a20

Browse filesBrowse files
Fix output
1 parent 774627c commit a334a20
Copy full SHA for a334a20

File tree

1 file changed

+13
-255
lines changed
Filter options

1 file changed

+13
-255
lines changed

‎03-dict-set/03-dict-set.ipynb

Copy file name to clipboardExpand all lines: 03-dict-set/03-dict-set.ipynb
+13-255Lines changed: 13 additions & 255 deletions
Original file line numberDiff line numberDiff line change
@@ -886,200 +886,57 @@
886886
},
887887
{
888888
"cell_type": "code",
889-
"execution_count": 76,
889+
"execution_count": 32,
890890
"metadata": {
891891
"pycharm": {
892892
"name": "#%%\n"
893893
},
894894
"scrolled": true
895895
},
896-
"outputs": [
897-
{
898-
"name": "stdout",
899-
"output_type": "stream",
900-
"text": [
901-
"a [(19, 48), (20, 53)]\r\n",
902-
"Although [(11, 1), (16, 1), (18, 1)]\r\n",
903-
"ambiguity [(14, 16)]\r\n",
904-
"and [(15, 23)]\r\n",
905-
"are [(21, 12)]\r\n",
906-
"aren [(10, 15)]\r\n",
907-
"at [(16, 38)]\r\n",
908-
"bad [(19, 50)]\r\n",
909-
"be [(15, 14), (16, 27), (20, 50)]\r\n",
910-
"beats [(11, 23)]\r\n",
911-
"Beautiful [(3, 1)]\r\n",
912-
"better [(3, 14), (4, 13), (5, 11), (6, 12), (7, 9), (8, 11), (17, 8), (18, 25)]\r\n",
913-
"break [(10, 40)]\r\n",
914-
"by [(1, 20)]\r\n",
915-
"cases [(10, 9)]\r\n",
916-
"complex [(5, 23)]\r\n",
917-
"Complex [(6, 1)]\r\n",
918-
"complicated [(6, 24)]\r\n",
919-
"counts [(9, 13)]\r\n",
920-
"dense [(8, 23)]\r\n"
921-
]
922-
}
923-
],
896+
"outputs": [],
924897
"source": [
925898
"# !python3 index0.py zen.txt"
926899
]
927900
},
928901
{
929-
"cell_type": "code",
902+
"cell_type": "markdown",
930903
"metadata": {
931904
"pycharm": {
932905
"name": "#%%\n"
933906
}
934907
},
935908
"source": [
936909
"#### Example 3-5. [`index.py`](index.py) uses `dict.setdefault` to fetch and update a list of word occurrences from the index in a single line; contrast with Example 3-4."
937-
],
938-
"execution_count": null,
939-
"outputs": []
910+
]
940911
},
941912
{
942913
"cell_type": "code",
943914
"execution_count": 33,
944915
"metadata": {
945-
"scrolled": true,
946-
"pycharm": {
947-
"name": "#%%\n"
948-
}
916+
"scrolled": true
949917
},
950-
"outputs": [
951-
{
952-
"name": "stdout",
953-
"output_type": "stream",
954-
"text": [
955-
"a [(19, 48), (20, 53)]\r\n",
956-
"Although [(11, 1), (16, 1), (18, 1)]\r\n",
957-
"ambiguity [(14, 16)]\r\n",
958-
"and [(15, 23)]\r\n",
959-
"are [(21, 12)]\r\n",
960-
"aren [(10, 15)]\r\n",
961-
"at [(16, 38)]\r\n",
962-
"bad [(19, 50)]\r\n",
963-
"be [(15, 14), (16, 27), (20, 50)]\r\n",
964-
"beats [(11, 23)]\r\n",
965-
"Beautiful [(3, 1)]\r\n",
966-
"better [(3, 14), (4, 13), (5, 11), (6, 12), (7, 9), (8, 11), (17, 8), (18, 25)]\r\n",
967-
"break [(10, 40)]\r\n",
968-
"by [(1, 20)]\r\n",
969-
"cases [(10, 9)]\r\n",
970-
"complex [(5, 23)]\r\n",
971-
"Complex [(6, 1)]\r\n",
972-
"complicated [(6, 24)]\r\n",
973-
"counts [(9, 13)]\r\n",
974-
"dense [(8, 23)]\r\n",
975-
"do [(15, 64), (21, 48)]\r\n",
976-
"Dutch [(16, 61)]\r\n",
977-
"easy [(20, 26)]\r\n",
978-
"enough [(10, 30)]\r\n",
979-
"Errors [(12, 1)]\r\n",
980-
"explain [(19, 34), (20, 34)]\r\n",
981-
"Explicit [(4, 1)]\r\n",
982-
"explicitly [(13, 8)]\r\n",
983-
"face [(14, 8)]\r\n",
984-
"first [(16, 41)]\r\n",
985-
"Flat [(7, 1)]\r\n",
986-
"good [(20, 55)]\r\n",
987-
"great [(21, 28)]\r\n",
988-
"guess [(14, 52)]\r\n",
989-
"hard [(19, 26)]\r\n",
990-
"honking [(21, 20)]\r\n",
991-
"idea [(19, 54), (20, 60), (21, 34)]\r\n",
992-
"If [(19, 1), (20, 1)]\r\n",
993-
"implementation [(19, 8), (20, 8)]\r\n",
994-
"implicit [(4, 25)]\r\n",
995-
"In [(14, 1)]\r\n",
996-
"is [(3, 11), (4, 10), (5, 8), (6, 9), (7, 6), (8, 8), (17, 5), (18, 16), (19, 23), (20, 23)]\r\n",
997-
"it [(15, 67), (19, 43), (20, 43)]\r\n",
998-
"let [(21, 42)]\r\n",
999-
"may [(16, 19), (20, 46)]\r\n",
1000-
"more [(21, 51)]\r\n",
1001-
"Namespaces [(21, 1)]\r\n",
1002-
"nested [(7, 21)]\r\n",
1003-
"never [(12, 15), (17, 20), (18, 10)]\r\n",
1004-
"not [(16, 23)]\r\n",
1005-
"Now [(17, 1)]\r\n",
1006-
"now [(18, 45)]\r\n",
1007-
"obvious [(15, 49), (16, 30)]\r\n",
1008-
"of [(1, 9), (14, 13), (21, 56)]\r\n",
1009-
"often [(18, 19)]\r\n",
1010-
"one [(15, 17), (15, 43), (21, 16)]\r\n",
1011-
"only [(15, 38)]\r\n",
1012-
"pass [(12, 21)]\r\n",
1013-
"Peters [(1, 27)]\r\n",
1014-
"practicality [(11, 10)]\r\n",
1015-
"preferably [(15, 27)]\r\n",
1016-
"purity [(11, 29)]\r\n",
1017-
"Python [(1, 12)]\r\n",
1018-
"re [(16, 58)]\r\n",
1019-
"Readability [(9, 1)]\r\n",
1020-
"refuse [(14, 27)]\r\n",
1021-
"right [(18, 38)]\r\n",
1022-
"rules [(10, 50)]\r\n",
1023-
"s [(19, 46), (21, 46)]\r\n",
1024-
"should [(12, 8), (15, 7)]\r\n",
1025-
"silenced [(13, 19)]\r\n",
1026-
"silently [(12, 26)]\r\n",
1027-
"Simple [(5, 1)]\r\n",
1028-
"Sparse [(8, 1)]\r\n",
1029-
"Special [(10, 1)]\r\n",
1030-
"special [(10, 22)]\r\n",
1031-
"t [(10, 20)]\r\n",
1032-
"temptation [(14, 38)]\r\n",
1033-
"than [(3, 21), (4, 20), (5, 18), (6, 19), (7, 16), (8, 18), (17, 15), (18, 32)]\r\n",
1034-
"that [(16, 10)]\r\n",
1035-
"The [(1, 1)]\r\n",
1036-
"the [(10, 46), (14, 4), (14, 34), (19, 4), (20, 4)]\r\n",
1037-
"There [(15, 1)]\r\n",
1038-
"those [(21, 59)]\r\n",
1039-
"Tim [(1, 23)]\r\n",
1040-
"to [(10, 37), (14, 49), (15, 61), (19, 31), (20, 31)]\r\n",
1041-
"ugly [(3, 26)]\r\n",
1042-
"Unless [(13, 1)]\r\n",
1043-
"unless [(16, 47)]\r\n",
1044-
"way [(15, 57), (16, 15)]\r\n",
1045-
"you [(16, 54)]\r\n",
1046-
"Zen [(1, 5)]\r\n"
1047-
]
1048-
}
1049-
],
918+
"outputs": [],
1050919
"source": [
1051920
"# python3 index.py zen.txt"
1052921
]
1053922
},
1054923
{
1055924
"cell_type": "markdown",
1056-
"metadata": {
1057-
"pycharm": {
1058-
"name": "#%% md\n"
1059-
}
1060-
},
925+
"metadata": {},
1061926
"source": [
1062927
"## Automatic handling of Missing Keys"
1063928
]
1064929
},
1065930
{
1066931
"cell_type": "markdown",
1067-
"metadata": {
1068-
"pycharm": {
1069-
"name": "#%% md\n"
1070-
}
1071-
},
932+
"metadata": {},
1072933
"source": [
1073934
"### `defaultdict`: Another take on missing keys"
1074935
]
1075936
},
1076937
{
1077938
"cell_type": "markdown",
1078-
"metadata": {
1079-
"pycharm": {
1080-
"name": "#%% md\n"
1081-
}
1082-
},
939+
"metadata": {},
1083940
"source": [
1084941
"#### Example 3-6. [`index_default.py`](index_default.py): using defaultdict instead of the setdefault method"
1085942
]
@@ -1093,108 +950,9 @@
1093950
"name": "#%%\n"
1094951
}
1095952
},
1096-
"outputs": [
1097-
{
1098-
"name": "stdout",
1099-
"output_type": "stream",
1100-
"text": [
1101-
"a [(19, 48), (20, 53)]\r\n",
1102-
"Although [(11, 1), (16, 1), (18, 1)]\r\n",
1103-
"ambiguity [(14, 16)]\r\n",
1104-
"and [(15, 23)]\r\n",
1105-
"are [(21, 12)]\r\n",
1106-
"aren [(10, 15)]\r\n",
1107-
"at [(16, 38)]\r\n",
1108-
"bad [(19, 50)]\r\n",
1109-
"be [(15, 14), (16, 27), (20, 50)]\r\n",
1110-
"beats [(11, 23)]\r\n",
1111-
"Beautiful [(3, 1)]\r\n",
1112-
"better [(3, 14), (4, 13), (5, 11), (6, 12), (7, 9), (8, 11), (17, 8), (18, 25)]\r\n",
1113-
"break [(10, 40)]\r\n",
1114-
"by [(1, 20)]\r\n",
1115-
"cases [(10, 9)]\r\n",
1116-
"complex [(5, 23)]\r\n",
1117-
"Complex [(6, 1)]\r\n",
1118-
"complicated [(6, 24)]\r\n",
1119-
"counts [(9, 13)]\r\n",
1120-
"dense [(8, 23)]\r\n",
1121-
"do [(15, 64), (21, 48)]\r\n",
1122-
"Dutch [(16, 61)]\r\n",
1123-
"easy [(20, 26)]\r\n",
1124-
"enough [(10, 30)]\r\n",
1125-
"Errors [(12, 1)]\r\n",
1126-
"explain [(19, 34), (20, 34)]\r\n",
1127-
"Explicit [(4, 1)]\r\n",
1128-
"explicitly [(13, 8)]\r\n",
1129-
"face [(14, 8)]\r\n",
1130-
"first [(16, 41)]\r\n",
1131-
"Flat [(7, 1)]\r\n",
1132-
"good [(20, 55)]\r\n",
1133-
"great [(21, 28)]\r\n",
1134-
"guess [(14, 52)]\r\n",
1135-
"hard [(19, 26)]\r\n",
1136-
"honking [(21, 20)]\r\n",
1137-
"idea [(19, 54), (20, 60), (21, 34)]\r\n",
1138-
"If [(19, 1), (20, 1)]\r\n",
1139-
"implementation [(19, 8), (20, 8)]\r\n",
1140-
"implicit [(4, 25)]\r\n",
1141-
"In [(14, 1)]\r\n",
1142-
"is [(3, 11), (4, 10), (5, 8), (6, 9), (7, 6), (8, 8), (17, 5), (18, 16), (19, 23), (20, 23)]\r\n",
1143-
"it [(15, 67), (19, 43), (20, 43)]\r\n",
1144-
"let [(21, 42)]\r\n",
1145-
"may [(16, 19), (20, 46)]\r\n",
1146-
"more [(21, 51)]\r\n",
1147-
"Namespaces [(21, 1)]\r\n",
1148-
"nested [(7, 21)]\r\n",
1149-
"never [(12, 15), (17, 20), (18, 10)]\r\n",
1150-
"not [(16, 23)]\r\n",
1151-
"Now [(17, 1)]\r\n",
1152-
"now [(18, 45)]\r\n",
1153-
"obvious [(15, 49), (16, 30)]\r\n",
1154-
"of [(1, 9), (14, 13), (21, 56)]\r\n",
1155-
"often [(18, 19)]\r\n",
1156-
"one [(15, 17), (15, 43), (21, 16)]\r\n",
1157-
"only [(15, 38)]\r\n",
1158-
"pass [(12, 21)]\r\n",
1159-
"Peters [(1, 27)]\r\n",
1160-
"practicality [(11, 10)]\r\n",
1161-
"preferably [(15, 27)]\r\n",
1162-
"purity [(11, 29)]\r\n",
1163-
"Python [(1, 12)]\r\n",
1164-
"re [(16, 58)]\r\n",
1165-
"Readability [(9, 1)]\r\n",
1166-
"refuse [(14, 27)]\r\n",
1167-
"right [(18, 38)]\r\n",
1168-
"rules [(10, 50)]\r\n",
1169-
"s [(19, 46), (21, 46)]\r\n",
1170-
"should [(12, 8), (15, 7)]\r\n",
1171-
"silenced [(13, 19)]\r\n",
1172-
"silently [(12, 26)]\r\n",
1173-
"Simple [(5, 1)]\r\n",
1174-
"Sparse [(8, 1)]\r\n",
1175-
"Special [(10, 1)]\r\n",
1176-
"special [(10, 22)]\r\n",
1177-
"t [(10, 20)]\r\n",
1178-
"temptation [(14, 38)]\r\n",
1179-
"than [(3, 21), (4, 20), (5, 18), (6, 19), (7, 16), (8, 18), (17, 15), (18, 32)]\r\n",
1180-
"that [(16, 10)]\r\n",
1181-
"The [(1, 1)]\r\n",
1182-
"the [(10, 46), (14, 4), (14, 34), (19, 4), (20, 4)]\r\n",
1183-
"There [(15, 1)]\r\n",
1184-
"those [(21, 59)]\r\n",
1185-
"Tim [(1, 23)]\r\n",
1186-
"to [(10, 37), (14, 49), (15, 61), (19, 31), (20, 31)]\r\n",
1187-
"ugly [(3, 26)]\r\n",
1188-
"Unless [(13, 1)]\r\n",
1189-
"unless [(16, 47)]\r\n",
1190-
"way [(15, 57), (16, 15)]\r\n",
1191-
"you [(16, 54)]\r\n",
1192-
"Zen [(1, 5)]\r\n"
1193-
]
1194-
}
1195-
],
953+
"outputs": [],
1196954
"source": [
1197-
"#!python index_default.py zen.txt"
955+
"# !python index_default.py zen.txt"
1198956
]
1199957
},
1200958
{
@@ -1757,7 +1515,7 @@
17571515
{
17581516
"data": {
17591517
"text/plain": [
1760-
"<dict_reversevalueiterator at 0x7f95ac5c5e40>"
1518+
"<dict_reversevalueiterator at 0x7fd2b88ca0c0>"
17611519
]
17621520
},
17631521
"execution_count": 58,
@@ -1897,7 +1655,7 @@
18971655
{
18981656
"data": {
18991657
"text/plain": [
1900-
"['bacon', 'eggs', 'spam']"
1658+
"['bacon', 'spam', 'eggs']"
19011659
]
19021660
},
19031661
"execution_count": 64,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.