-
-
Notifications
You must be signed in to change notification settings - Fork 440
Open
Description
How could the content be improved?
Hi Carpentry Team,
When working through the "Lists" episode I noticed potential for streamlining and isolating some proposed concepts.
The episode contains a section about using append to add items to a list.
The last bullet point introduces the function extend, which is an important and often used utility.
However, I see some problems with the current state:
- While in some wide sense, the title
Appending items to a list lengthens itis also true forextend, it is more fitting to introduceappendsolely, as it is the user's first contact to list extension. - The description and showcase of
extendis actually longer than the presentation ofappend. - The proposed
extendexample withmiddle_aged_primesandteen_primesmight be a bit weird and out of context. - Additionally, the
extendexample introduces the concept of nested lists and mixed-type list membership implicitly, which might not be the right place.
Proposal:
- Extract the
extendfunctionality into a separate section with the context of merging lists. - Make the example more intuitive.
- Use the opportunity to introduce the
+operator for list merging. - Move the concept of nested lists to the section about different types in lists.
For 1. and 2.:
## Multiple lists can be combined.
- `extend` is a list *method* like `append` but allows you to combine two lists. For example:
primes = [2, 3, 5, 7]
more_primes = [11, 13, 17, 19]
print('primes is currently:', primes)
primes.extend(more_primes)
print('primes has now become:', primes)primes is currently: [2, 3, 5, 7]
primes has now become: [2, 3, 5, 7, 11, 13, 17, 19]
For 3.:
- We can also combine lists using the `+` operator, but instead of altering an existing list, it creates a new one.
primes = [2, 3, 5, 7]
more_primes = [11, 13, 17, 19]
combined_primes = primes + more_primes
print('combined_primes is now:', combined_primes)combined_primes is now: [2, 3, 5, 7, 11, 13, 17, 19]
For 4. add to the types section:
- This implies that lists can store other lists, allowing arbitrary nested lists.
more_goals = [4, 'Explore lists.', [5, 'Understand lists within lists.', [6, 'Master Python lists.']]]The changes are also contained in a PR #679 I have made previously.
I apologize for the inconvenience caused, as I didn't open an issue first.
I agree that the proposed changes should be talked about with the community.
Cheers,
Tobias
Which part of the content does your suggestion apply to?
Metadata
Metadata
Assignees
Labels
No labels