Skip to content

Commit 1c9b44c

Browse files
authored
[Tuples Concept and Exercise]: Typo, grammar, & formatting fixes for Tuples Concept & Exercise. (exercism#4175)
* Typo, grammar, and formatting fixes for tuples concept and exercise. * Indentation and other corrections from code review.
1 parent fa51110 commit 1c9b44c

4 files changed

Lines changed: 24 additions & 32 deletions

File tree

concepts/tuples/about.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ To include both keys and values in a tuple made from a dictionary, use `<dict>.i
5757
which will return an iterator of (`key`, `value`) `tuples`.
5858

5959
```python
60-
source_data = {"fish": "gold",
61-
"monkey": "brown"}
60+
>>> source_data = {"fish": "gold", "monkey": "brown"}
6261

6362
>>> multiple_elements_dict_1 = tuple(source_data)
6463
('fish', 'monkey')
@@ -81,7 +80,7 @@ Because the `tuple()` constructor only takes _iterables_ (or nothing) as argumen
8180
```
8281

8382
Note that generally parentheses are **not** required to create a `tuple` literal - only commas.
84-
However, using `(<element)1>, <element_2>)` is considered more readable in most circumstances.
83+
However, using `(<element_1>, <element_2>)` is considered more readable in most circumstances.
8584
Parentheses are also required in cases of ambiguity, such as an empty or one-item tuple or where a function takes a tuple as an argument.
8685

8786
```python
@@ -102,7 +101,7 @@ Other data structures can be included as `tuple` elements, including other `tupl
102101
(["fish", "gold", "monkey", "brown", "parrot", "grey"], ("fish", "mammal", "bird"))
103102
```
104103

105-
Tuples can be concatenated using plus `+` operator, which unpacks each `tuple` creating a new, combined `tuple`.
104+
Tuples can be concatenated using plus `+` operator, which unpacks each `tuple`, creating a new, combined `tuple`.
106105

107106
```python
108107
>>> new_via_concatenate = ("George", 5) + ("cat", "Tabby")
@@ -122,8 +121,7 @@ Indexes can be from **`left`** --> **`right`** (_starting at zero_) or **`right`
122121
Tuples can also be copied in whole or in part via _slice notation_ or using `<tuple>.copy()`.
123122

124123
```python
125-
126-
>>> student_info = ("Alyssa", "grade 3", "female", 8 )
124+
>>> student_info = ("Alyssa", "grade 3", "female", 8)
127125

128126
#name is at index 0 or index -4
129127
>>> student_name = student_info[0]
@@ -146,19 +144,17 @@ Elements inside tuples can be _iterated over_ in a loop using `for item in <tupl
146144
If both indexes and values are needed, `for index, item in enumerate(<tuple>)` can be used.
147145

148146
```python
149-
>>> student_info = ("Alyssa", "grade 3", "female", 8 )
147+
>>> student_info = ("Alyssa", "grade 3", "female", 8)
150148
>>> for item in student_info:
151149
... print(item)
152-
153150
...
154151
Alyssa
155152
grade 3
156153
female
157154
8
158155

159156
>>> for index, item in enumerate(student_info):
160-
... print("Index is: " + str(index) + ", value is: " + str(item) +".")
161-
157+
... print("Index is: " + str(index) + ", value is: " + str(item) + ".")
162158
...
163159
Index is: 0, value is: Alyssa.
164160
Index is: 1, value is: grade 3.
@@ -172,9 +168,7 @@ Index is: 3, value is: 8.
172168
Tuples are often used as _records_ containing data that is _organizationally_ or _conceptually_ homogeneous and treated as a single unit of information -- even if individual elements are of _heterogeneous_ data types.
173169

174170
```python
175-
176-
>>> student_info = ("Alyssa", "grade 3", "female", 8 )
177-
171+
>>> student_info = ("Alyssa", "grade 3", "female", 8)
178172
```
179173

180174
Tuples are also used when homogeneous immutable sequences of data are needed for [`hashability`][hashability], storage in a `set`, or creation of keys in a dictionary.
@@ -183,29 +177,27 @@ Note that while `tuples` are in most cases _immutable_, because they can contain
183177
Using a mutable data type within a `tuple` will make the enclosing `tuple` **un-hashable**.
184178

185179
```python
186-
187180
>>> cmyk_color_map = {
188-
(.69, .3, .48, .1) : ("Teal 700", (59, 178, 146), 0x3BB292),
189-
(0, .5, 1, 0) : ("Pantone 151", (247, 127, 1), 0xF77F01),
190-
(.37, .89, 0, .44) : ("Pantone 267", (89, 16, 142), 0x59108E),
191-
(0, 1, .46, .45) : ("Pantone 228", (140, 0, 76), 0x8C004C)
192-
}
193-
194-
>>>> unique_rgb_colors = {
195-
(59, 178, 146),
196-
(247, 127, 1),
197-
(89, 16, 142),
198-
(140, 0, 76),
199-
(76, 0, 140)
200-
}
181+
(.69, .3, .48, .1) : ("Teal 700", (59, 178, 146), 0x3BB292),
182+
(0, .5, 1, 0) : ("Pantone 151", (247, 127, 1), 0xF77F01),
183+
(.37, .89, 0, .44) : ("Pantone 267", (89, 16, 142), 0x59108E),
184+
(0, 1, .46, .45) : ("Pantone 228", (140, 0, 76), 0x8C004C)
185+
}
186+
187+
>>> unique_rgb_colors = {
188+
(59, 178, 146),
189+
(247, 127, 1),
190+
(89, 16, 142),
191+
(140, 0, 76),
192+
(76, 0, 140)
193+
}
201194

202195
>>> teal_700 = hash((59, 178, 146))
203196

204197
>>> teal_700 = hash(("Pantone 228", [(140, 0, 76), 0x8C004C]))
205198
Traceback (most recent call last):
206199
File "<stdin>", line 1, in <module>
207200
TypeError: unhashable type: 'list'
208-
209201
```
210202

211203
## Extended tuples and related data types

exercises/concept/tisbury-treasure-hunt/.docs/hints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## General
44

55

6-
- [Tuples][tuples] are immutable [sequence Types][sequence types] that can contain any data type.
6+
- [Tuples][tuples] are immutable [sequence types][sequence types] that can contain any data type.
77
- Tuples are [iterable][iterable]. If you need indexes as well as values, use [`enumerate()`][enumerate]
88
- Elements within tuples can be accessed via [bracket notation][bracket notation], using a zero-based index from the left, or -1 from the right. Other [Common Sequence Operations][common sequence operations] can also be used when working with tuples.
99

@@ -32,7 +32,7 @@
3232
- Remember: tuples are _immutable_, but the contents can be accessed via _index_ using _bracket notation_.
3333
- Tuples don't have to use parentheses unless there is _ambiguity_.
3434
- Python has multiple methods of string formatting. [`str.format()`][str.format] and [`f-strings`][f-strings] are two very common ones.
35-
- There are multiple textual formatting options available via Pythons [`format specification mini-language`][format specification mini-language].
35+
- There are multiple textual formatting options available via Python's [`format specification mini-language`][format specification mini-language].
3636

3737

3838
[bracket notation]: https://stackoverflow.com/questions/30250282/whats-the-difference-between-the-square-bracket-and-dot-notations-in-python

exercises/concept/tisbury-treasure-hunt/.meta/exemplar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def compare_records(azara_record, rui_record):
3131
"""Compare two record types and determine if their coordinates match.
3232
3333
Parameters:
34-
azara_record (tuple): A (treasure, coordinate) pair.
34+
azara_record (tuple): A (treasure, coordinate) pair.
3535
rui_record (tuple): A (location, tuple(coordinate_1, coordinate_2), quadrant) trio.
3636
3737
Returns:

exercises/concept/tisbury-treasure-hunt/tuples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def compare_records(azara_record, rui_record):
3131
"""Compare two record types and determine if their coordinates match.
3232
3333
Parameters:
34-
azara_record (tuple): A (treasure, coordinate) pair.
34+
azara_record (tuple): A (treasure, coordinate) pair.
3535
rui_record (tuple): A (location, tuple(coordinate_1, coordinate_2), quadrant) trio.
3636
3737
Returns:

0 commit comments

Comments
 (0)