python-novice-inflammation icon indicating copy to clipboard operation
python-novice-inflammation copied to clipboard

Two discussions of copying mutable objects in episode 3?

Open edbennett opened this issue 6 years ago • 1 comments

I was tripped up teaching this week when working through episode 3—there's a long sidebar talking about mutability, most of which is devoted to showing how to make copies of lists without accidental aliasing. Then a few paragraphs later, there's an almost identical discussion of avoiding this problem, with a different example, and avoiding the word mutable. Having not noticed this beforehand, I ended up repeating myself largely, since I assumed that there would be something new to say, and then there wasn't.

Should these two sections be consolidated into one discussion? (Perhaps by removing "how to correctly create copies" from the sidebar, and mentioning that it will be discussed further down the page?) Removing some duplicated content would also go a (very small) way towards helping with the time constraints with this long lesson.

edbennett avatar Jan 31 '19 20:01 edbennett

I second this idea. I'm very fond of teaching the difference between copying and just assigning a list to a new variable name. Especially since it seems like something previous users of R could get caught on, where its less of an issue. However, Ch-Ch-Ch-Ch-Changes does seem like it can be split up. Maybe we could try something like this?

  1. Move the first two paragraphs of Ch-Ch-Ch-Ch-Changes, which talk about mutability, to be part of the standard lesson right after
name = 'Darwin'
name[0] = 'd'
  1. Drop the salsa example of Ch-Ch-Ch-Ch-Changes. I think it is a nice example but seems to be a lot of typing to get the premise across.

  2. Add an assignment example to the mutability section at the bottom of the lesson

odds = [1, 3, 5, 7, 9]
primes = odds
primes[-1] = 11
print('primes:', primes)
print('odds:', odds)
primes.append(2)
print('primes:', primes)
print('odds:', odds)

AnthonyOfSeattle avatar Jul 12 '19 01:07 AnthonyOfSeattle