0% found this document useful (0 votes)
5 views3 pages

CS1101 Unit 6 Assignment

Uploaded by

marlenalomeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

CS1101 Unit 6 Assignment

Uploaded by

marlenalomeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 1101 Discussion Assignment 6 Marlena Lomeli

When you say two items are equivalent, you’re saying they have the same value. When you say

two items are identical, you’re saying they are the same exact item. So, you could say that even

if two items are equivalent, they are not identical. But if they are identical, then they are

equivalent. Look at the following example:

Using my example of His_Friends and Her_Friends, I'll describe how objects, references, and

aliasing relate to them. First, each list is an independent object in memory. In memory is within

Python. They are both the same type, which is a list, but they are distinct and occupy separate

memory locations.

Then we have references. Each variable, ‘His_Friends’ and ‘Her_Friends’, reference its

respective list. When you assign a list to a variable, you’re creating a reference to that list. In the

memory, these references point to the objects (the lists) that they represent.
Finally, aliasing. With my specific example, aliasing is not present, so any changes made to one

list won’t affect the other. But if I modify my lists? Here’s an example:

In this case, both ‘His Friends’ and ‘Her Friends’ now reference the same list, so when you

modify one, the other list is also affected because they are now aliases.

For my function, I have it taking two parameters: ‘friends_list’, which represents the list to be

modified, and ‘new_friend’, which represents the friend to add. I’m still using the same lists of

‘His_Friends’ and ‘Her_Friends’ from my previous examples. I’ve used ‘His_Friends’ as the

first argument and I want to add a new friend, Chase, to the list, so that’s my second argument. I

call the function. It should now add Chase to the end of ‘His_Friends’. I use the ‘print’ statement

and the output is now ['Kales', 'Jose', 'Jacob', ‘Chase’]. I also print ‘Her_Friends’ and the output

is ['Kales', 'Jose', 'Jacob'], without Chase at the end. This is because though both variable names

reference the same list, they are different objects. I can make an addition, or deletion, to either

one, and they won’t affect each other.


For my question, I thought of it while reading section 10.8 in Think Python: when removing

more than one element and using del with a slice index, how would you del multiple ranges? For

example, a list of ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'], and I want to remove

indices 2-6 and 8-10?

References:

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.

https://greenteapress.com/thinkpython2/thinkpython2.pdf

You might also like