Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List Introduction: Extract extend functionality from section about append #680

Open
saiboxx opened this issue Apr 30, 2024 · 0 comments
Open

Comments

@saiboxx
Copy link

saiboxx commented Apr 30, 2024

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 it is also true for extend, it is more fitting to introduce append solely, as it is the user's first contact to list extension.
  • The description and showcase of extend is actually longer than the presentation of append.
  • The proposed extend example with middle_aged_primes and teen_primes might be a bit weird and out of context.
  • Additionally, the extend example introduces the concept of nested lists and mixed-type list membership implicitly, which might not be the right place.

Proposal:

  1. Extract the extend functionality into a separate section with the context of merging lists.
  2. Make the example more intuitive.
  3. Use the opportunity to introduce the + operator for list merging.
  4. 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?

http://swcarpentry.github.io/python-novice-gapminder/11-lists.html#appending-items-to-a-list-lengthens-it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant