Spaces:
Sleeping
Sleeping
changes: according to review comments
Browse files- Python/phase_1/collections.py +23 -105
Python/phase_1/collections.py
CHANGED
|
@@ -68,20 +68,21 @@ def _(sample_list):
|
|
| 68 |
|
| 69 |
@app.cell
|
| 70 |
def _(sample_list):
|
| 71 |
-
sample_list.append(6) # Add item to end
|
| 72 |
-
sample_list
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
@app.cell
|
| 77 |
-
def _(
|
| 78 |
-
|
| 79 |
return
|
| 80 |
|
| 81 |
|
| 82 |
@app.cell
|
| 83 |
-
def _(
|
| 84 |
-
|
| 85 |
return
|
| 86 |
|
| 87 |
|
|
@@ -89,68 +90,42 @@ def _(sample_list):
|
|
| 89 |
def _(mo):
|
| 90 |
mo.md(
|
| 91 |
"""
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
"""
|
| 96 |
)
|
| 97 |
return
|
| 98 |
|
| 99 |
|
| 100 |
@app.cell
|
| 101 |
-
def _(
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
return item, items
|
| 105 |
|
| 106 |
|
| 107 |
@app.cell
|
| 108 |
-
def _(
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
mo.md(f"Your list: {items.value}")
|
| 113 |
-
],
|
| 114 |
-
justify="space-between"
|
| 115 |
-
)
|
| 116 |
-
return
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
@app.cell(hide_code=True)
|
| 120 |
-
def _(mo):
|
| 121 |
-
_text = mo.md("""
|
| 122 |
-
- Try entering different types of items
|
| 123 |
-
- Watch how the list updates in real-time
|
| 124 |
-
|
| 125 |
-
This is a great way to experiment with list creation!
|
| 126 |
-
""")
|
| 127 |
-
mo.accordion({"💡 Interactive List Builder Tips": _text})
|
| 128 |
-
return
|
| 129 |
|
| 130 |
|
| 131 |
@app.cell(hide_code=True)
|
| 132 |
def _(mo):
|
| 133 |
-
mo.md(
|
| 134 |
-
"""
|
| 135 |
-
## Tuples
|
| 136 |
-
|
| 137 |
-
Tuples are immutable sequences. They're like lists that can't be changed after creation:
|
| 138 |
-
"""
|
| 139 |
-
)
|
| 140 |
return
|
| 141 |
|
| 142 |
|
| 143 |
@app.cell
|
| 144 |
def _():
|
| 145 |
-
|
| 146 |
-
|
| 147 |
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
x, y = coordinates # Tuple unpacking
|
| 152 |
-
x
|
| 153 |
-
return x, y
|
| 154 |
|
| 155 |
|
| 156 |
@app.cell(hide_code=True)
|
|
@@ -193,63 +168,6 @@ def _(person):
|
|
| 193 |
return
|
| 194 |
|
| 195 |
|
| 196 |
-
@app.cell(hide_code=True)
|
| 197 |
-
def _(mo):
|
| 198 |
-
mo.md(
|
| 199 |
-
"""
|
| 200 |
-
### Try marimo's Dictionary Interface!
|
| 201 |
-
|
| 202 |
-
Create your own dictionary using marimo's interactive elements:
|
| 203 |
-
"""
|
| 204 |
-
)
|
| 205 |
-
return
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
@app.cell
|
| 209 |
-
def _(mo):
|
| 210 |
-
key1 = mo.ui.text(placeholder="Key 1")
|
| 211 |
-
value1 = mo.ui.text(placeholder="Value 1")
|
| 212 |
-
key2 = mo.ui.text(placeholder="Key 2")
|
| 213 |
-
value2 = mo.ui.text(placeholder="Value 2")
|
| 214 |
-
|
| 215 |
-
dictionary = mo.ui.dictionary(
|
| 216 |
-
{
|
| 217 |
-
"First key": key1,
|
| 218 |
-
"First value": value1,
|
| 219 |
-
"Second key": key2,
|
| 220 |
-
"Second value": value2,
|
| 221 |
-
}
|
| 222 |
-
)
|
| 223 |
-
|
| 224 |
-
return dictionary, key1, key2, value1, value2
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
@app.cell
|
| 228 |
-
def _(dictionary, mo):
|
| 229 |
-
mo.hstack(
|
| 230 |
-
[
|
| 231 |
-
dictionary,
|
| 232 |
-
mo.md(f"Your dictionary: {dictionary.value}")
|
| 233 |
-
],
|
| 234 |
-
justify="space-between"
|
| 235 |
-
)
|
| 236 |
-
return
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
@app.cell(hide_code=True)
|
| 240 |
-
def _(mo):
|
| 241 |
-
_text = mo.md("""Enter key-value pairs to build your dictionary
|
| 242 |
-
|
| 243 |
-
- Watch how the dictionary updates as you type
|
| 244 |
-
|
| 245 |
-
- Try different types of values
|
| 246 |
-
|
| 247 |
-
This interactive builder helps understand dictionary structure!
|
| 248 |
-
""")
|
| 249 |
-
mo.accordion({"💡 Dictionary Builder Tips": _text})
|
| 250 |
-
return
|
| 251 |
-
|
| 252 |
-
|
| 253 |
@app.cell(hide_code=True)
|
| 254 |
def _(mo):
|
| 255 |
mo.md(
|
|
|
|
| 68 |
|
| 69 |
@app.cell
|
| 70 |
def _(sample_list):
|
| 71 |
+
# sample_list.append(6) # Add item to end
|
| 72 |
+
extended_list = sample_list + [6] # concatenate two lists
|
| 73 |
+
extended_list
|
| 74 |
+
return (extended_list,)
|
| 75 |
|
| 76 |
|
| 77 |
@app.cell
|
| 78 |
+
def _(extended_list):
|
| 79 |
+
extended_list[0] # Access first element
|
| 80 |
return
|
| 81 |
|
| 82 |
|
| 83 |
@app.cell
|
| 84 |
+
def _(extended_list):
|
| 85 |
+
extended_list[-1] # Access last element
|
| 86 |
return
|
| 87 |
|
| 88 |
|
|
|
|
| 90 |
def _(mo):
|
| 91 |
mo.md(
|
| 92 |
"""
|
| 93 |
+
## Tuples
|
| 94 |
|
| 95 |
+
Tuples are immutable sequences. They're like lists that can't be changed after creation:
|
| 96 |
"""
|
| 97 |
)
|
| 98 |
return
|
| 99 |
|
| 100 |
|
| 101 |
@app.cell
|
| 102 |
+
def _():
|
| 103 |
+
coordinates = (10, 20)
|
| 104 |
+
return (coordinates,)
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
@app.cell
|
| 108 |
+
def _(coordinates):
|
| 109 |
+
x, y = coordinates # Tuple unpacking
|
| 110 |
+
x
|
| 111 |
+
return x, y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
@app.cell(hide_code=True)
|
| 115 |
def _(mo):
|
| 116 |
+
mo.md("""#### Tuple concatenation""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
return
|
| 118 |
|
| 119 |
|
| 120 |
@app.cell
|
| 121 |
def _():
|
| 122 |
+
tuple1 = (1, 2, 3)
|
| 123 |
+
tuple2 = (4, 5, 6)
|
| 124 |
|
| 125 |
+
tuple3 = tuple1 + tuple2
|
| 126 |
|
| 127 |
+
tuple3
|
| 128 |
+
return tuple1, tuple2, tuple3
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
@app.cell(hide_code=True)
|
|
|
|
| 168 |
return
|
| 169 |
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
@app.cell(hide_code=True)
|
| 172 |
def _(mo):
|
| 173 |
mo.md(
|