Skip to content

Commit 72bbafb

Browse files
2/23/25 strings 05 ipynb
1 parent 7d95e48 commit 72bbafb

5 files changed

Lines changed: 267 additions & 49 deletions

File tree

lessons/02_Loops/03a_Lists.ipynb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,19 @@
308308
},
309309
{
310310
"cell_type": "code",
311-
"execution_count": null,
311+
"execution_count": 1,
312312
"id": "9f82ddae",
313313
"metadata": {},
314-
"outputs": [],
314+
"outputs": [
315+
{
316+
"name": "stdout",
317+
"output_type": "stream",
318+
"text": [
319+
"['One', 'Two', 'Three', 'Four']\n",
320+
"['One', 'Two', 'Three', 'Four']\n"
321+
]
322+
}
323+
],
315324
"source": [
316325
"# split a string at spaces, the default\n",
317326
"s = 'One Two Three Four'\n",

lessons/02_Loops/03c_Tuples.ipynb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@
7373
},
7474
{
7575
"cell_type": "code",
76-
"execution_count": null,
76+
"execution_count": 1,
7777
"metadata": {},
78-
"outputs": [],
78+
"outputs": [
79+
{
80+
"name": "stdout",
81+
"output_type": "stream",
82+
"text": [
83+
"1\n",
84+
"(3, 4)\n"
85+
]
86+
}
87+
],
7988
"source": [
8089
"t = (1, 2, 3, 4, 5) \n",
8190
"\n",
@@ -93,7 +102,7 @@
93102
],
94103
"metadata": {
95104
"kernelspec": {
96-
"display_name": ".venv",
105+
"display_name": "Python 3",
97106
"language": "python",
98107
"name": "python3"
99108
},
@@ -107,7 +116,7 @@
107116
"name": "python",
108117
"nbconvert_exporter": "python",
109118
"pygments_lexer": "ipython3",
110-
"version": "3.12.0"
119+
"version": "3.12.4"
111120
}
112121
},
113122
"nbformat": 4,

lessons/02_Loops/04a_Indexing_and_Slicing.ipynb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
},
1818
{
1919
"cell_type": "code",
20-
"execution_count": null,
20+
"execution_count": 1,
2121
"metadata": {},
22-
"outputs": [],
22+
"outputs": [
23+
{
24+
"name": "stdout",
25+
"output_type": "stream",
26+
"text": [
27+
"red\n",
28+
"blue\n",
29+
"orange\n"
30+
]
31+
}
32+
],
2333
"source": [
2434
"# Indexing ( Run Me! )\n",
2535
"\n",
@@ -46,9 +56,19 @@
4656
},
4757
{
4858
"cell_type": "code",
49-
"execution_count": null,
59+
"execution_count": 2,
5060
"metadata": {},
51-
"outputs": [],
61+
"outputs": [
62+
{
63+
"name": "stdout",
64+
"output_type": "stream",
65+
"text": [
66+
"[1:3] ['blue', 'black']\n",
67+
"[:2] ['red', 'blue']\n",
68+
"[2:] ['black', 'orange']\n"
69+
]
70+
}
71+
],
5272
"source": [
5373
"# Slicing lists (Run Me!)\n",
5474
"\n",
@@ -153,7 +173,7 @@
153173
],
154174
"metadata": {
155175
"kernelspec": {
156-
"display_name": ".venv",
176+
"display_name": "Python 3",
157177
"language": "python",
158178
"name": "python3"
159179
},
@@ -167,7 +187,7 @@
167187
"name": "python",
168188
"nbconvert_exporter": "python",
169189
"pygments_lexer": "ipython3",
170-
"version": "3.11.6"
190+
"version": "3.12.4"
171191
}
172192
},
173193
"nbformat": 4,

lessons/02_Loops/04b_List_Story.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,41 @@
66
77
"""
88

9-
words = ['Once', '👦', 'upon', '🐕', 'park', 'met', 'with', 'a', 'the',
10-
'time', 'to', 'who', '🐈', '👧', 'and', 'went', 'had', 'play', '⚽.', 'they']
9+
words = ['Once', '👦', 'upon', '🐕', 'park.', 'met', 'with', 'a', 'the',
10+
'time', 'to', 'who', '🐈', '👧', 'and', 'went', 'had', 'play', '⚽', 'they']
11+
# once 0 upon 2 a 7 time 9 a 7 boy 1 who 11 had 16 a 7 dog 3 and 14 a 7 girl 13 who 11 had 16 a 7 cat 12 met 5 and 14 went 15 to 10 play 17 with 6 a 7 ball 15.
1112

12-
story = []
1313

14+
story = [(words[0])]
15+
story.append(words[2])
16+
story.append(words[7])
17+
story.append(words[9])
18+
story.append(words[7])
19+
story.append(words[1])
20+
story.append(words[11])
21+
story.append(words[16])
22+
story.append(words[7])
23+
story.append(words[3])
24+
story.append(words[14])
25+
story.append(words[7])
26+
story.append(words[13])
27+
story.append(words[11])
28+
story.append(words[16])
29+
story.append(words[7])
30+
story.append(words[12])
31+
story.append(words[5])
32+
story.append(words[14])
33+
story.append(words[15])
34+
story.append(words[10])
35+
story.append(words[17])
36+
story.append(words[6])
37+
story.append(words[7])
38+
story.append(words[18])
39+
story.append('at')
40+
story.append(words[8])
41+
story.append(words[4])
1442
# Create a story using the words in the list
1543

44+
1645
# Display the story to the user
1746
print(' '.join(story))

0 commit comments

Comments
 (0)