Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

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??

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

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.
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?
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.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Ah ok, I missed that somehow. Thanks!
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.
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)
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?
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".
Thanks for the answer, it makes sense.

Not the answer you are looking for?

Search for more explanations.

Ask your own question