Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

ricketybridge Group Title

Has anyone done quiz 1? I'm confused by the answer to 1.5: "Let L be a list, each element of which is a list of ints. In Python, the assignment statement L[0][0] = 3 mutates the list L." Supposedly the answer is: "FALSE, it mutates the list at L[0]." Is there a word missing or something? If L[0] is mutated, isn't L as a whole considered mutated??

  • 5 months ago
  • 5 months ago

  • This Question is Closed
  1. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Not really. L[0] is a list in it's own right. L only contains a bunch of lists, one of which was mutated, but nothing directly changed for L. The mutation was to one of L[0]'s integers.

    • 4 months ago
  2. ricketybridge Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    That seems so debatable. Again, since L contains the mutated list... Do you have a source that contains that explanation? Does it have something to do with the way the list is stored in memory?

    • 4 months ago
  3. seandisanti Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I don't remember which video it is unfortunately, but in one of the early ones the Prof spends some time on this. Basically think of a list as a named collection. A list contained in another list is still just a named collection, not necessarily the contents of said collection. Here's an example, say you have a list of your possessions broken up into categories. One category could be your clothes. If you get a new shirt, the contents of the collection have changed, but the high level list hasn't actually changed, because you've already listed your clothes as one whole collection.

    • 4 months ago
  4. ricketybridge Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ah ok, I missed that somehow. Thanks!

    • 4 months ago
  5. Ante Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    As far as I understand the implementation, the list object consists of a bunch of pointers pointing to other elements in memory. So as long as L's pointer at 0 points to the same list object, L is considered unchanged. Although, to be fair, I'm still having trouble fully understanding the concept myself.

    • 4 months ago
  6. seandisanti Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    It sounds like you've just about got it, Ante. Just keep in mind that while your parent list can be a list of different types of data, each element can only contain one thing. You cannot simultaneously store a list AND it's contents in a single element. so the sub list as far python is concerned is nothing more than another named collection (whose contents it doesn't care about)

    • 4 months ago
  7. Ante Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for responding to that. Lists and tuples still confuse me. Is is correct to say that the main difference between them is that tuples take up an actual section in memory where all their elements are stored as bit strings and list objects themselves only contain references to other memory sections?

    • 4 months ago
  8. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    They're probably both implemented with memory pointers. From a Python programmer's perspective, the main difference between lists and tuples is that lists are mutable ( can be changed ), and tuples are immutable ( can't be changed ). If you "change" a tuple, you actually create a new tuple. A list is changed "in place".

    • 4 months ago
  9. Ante Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the answer, it makes sense.

    • 4 months ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.