Тёмный

5. Tuples, Lists, Aliasing, Mutability, and Cloning 

MIT OpenCourseWare
Подписаться 5 млн
Просмотров 222 тыс.
50% 1

MIT 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016
View the complete course: ocw.mit.edu/6-0001F16
Instructor: Dr. Ana Bell
In this lecture, Dr. Bell introduces compound data types, such as lists and tuples, and explains the concepts of aliasing, mutability, and cloning.
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu

Опубликовано:

 

14 фев 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 151   
@user-fl7vs4ed6l
@user-fl7vs4ed6l 3 года назад
pre labeling ​​0:01:27 Content of Lecture05 0:02:32​ New data type : Tuple 0:04:04 tuple slicing 0:05:35 tuple swapping 0:08:00 0:09:09 Manipulating tuples 0:13:00 ​0:12:00 ​0:15:31​ New data type : List 0:16:00 0:18:00 0:19:43 Operation on list 0:20:00 ​0:22:00 0:23:15 Operation on list ​0:26:55 convert list to string and back 0:28:00​ 0:29:16 Operation on list 0:31:52 ​An analogy 0:34:04 idea of Aliasing ​ 0:36:54 Idea of Mutate ​0:38:45​ Nested List 0:40:17 Mutation and iteration try this python tour
@leixun
@leixun 4 года назад
*My takeaways:* 1. Introduce compound data type 1:05: tuple and list. 2. String of a sequence of character data, tuple is a sequence of data in any type 1:35 and is immutable meaning that we cannot change it once we created it. 3. Why we want to use tuple 5:20. 4. List is a sequence of data in any type 14:55 and it mutable. 5. Aliases 34:00. 6. Cloning 35:15. 7. Sorting lists .sort() vs sorted() 36:30.
@algemmegla9002
@algemmegla9002 3 года назад
39:56 Mutation and Iteration. :D
@JacobKrajewski
@JacobKrajewski 5 лет назад
The person that edited this video did not do as well as the other, previous lectures. When she is literally pointing at the board, the person kept showing us video of Ana, as she is directing attention away from her to the slides... And then didn't show the slides after she was done talking. The other videos were all done really well by contrast.
@kaiwalpanchal5872
@kaiwalpanchal5872 3 года назад
came to say that exactly
@frankhuang5095
@frankhuang5095 3 года назад
Thank you MIT for providing such invaluable content to the public! Thank you!
@percih70
@percih70 6 лет назад
Python Tutor is such a good idea, it really helps show the concepts, well worth trying.
@Iain.G.D.B
@Iain.G.D.B 2 года назад
Great tutor and lessons however I would like a picture in picture of her and to be able to see what she is pointing at on the screen. hard to follow when you cannot see what she is pointing at.
@user-pe9qg3hg3k
@user-pe9qg3hg3k 2 года назад
Dr Ana Bell is absolutely phenomenal at what she does. What an amazing explanation again. I can't believe MIT has such high quality content up there available for free.
@kararkhan9822
@kararkhan9822 3 года назад
Thank you MIT , I am a non-IT student and understood everything.You are doing a great Job!! So far completed 2 courses taught by MIT online learned Alot ;)
@aritrachatterjee8057
@aritrachatterjee8057 5 лет назад
Thank you, Dr. Ana for making OOPs and Inheritance so simple. I could not get concept at first when i was going through MIT 6.00. But now i am equipped with the understanding and assignment problem(6.00) is "walk in the park ". Thank You. May Cosmos bless you with more knowledge...
@jaimemontero234
@jaimemontero234 2 года назад
Good lectures , clear slides and Dr. Ana Bell very , very good professor . Tanks MIT to give us thats extraordinarys open courses .
@Liaomiao
@Liaomiao 6 лет назад
camera could really focus on the slides a lot more
@garthhh
@garthhh 6 лет назад
You can download them in PDF format from the link in the description and follow along that way
@l_combo
@l_combo 6 лет назад
or do picture in picture, you get that when you do the EDX version of this course (also free but more structured)
@911Dagur
@911Dagur 6 лет назад
I assume she is talking about when the teacher points at the slides to show the students something with her cursor/laser pen and the camera stays on the professor. Makes it kind of hard to be fully aware of what she is referring to when she says "right here" or "over there". They should rather film the slides more to show what she points at on the slides.
@marklvrd
@marklvrd 5 лет назад
There is really no point to looking at the Professor, unless they are using the board.
@jetspray3
@jetspray3 5 лет назад
Cameraman did a really poor job.
@TheFootballPlaya
@TheFootballPlaya 2 года назад
great video. python, while it's syntax is simple, that simplicity in some ways serves to detract from what is actually happening and how things are processed. It's more apparent when you compare python operations to something like that of c++, where you realize how much python does for you. Other than information hiding, it's a lovely language.
@jasonzhang6534
@jasonzhang6534 9 месяцев назад
Thanks for the video. It really helps me to fully understand the difference between a tuple and a list.
@akbarrauf2741
@akbarrauf2741 7 лет назад
thank you ,mit
@aritrachatterjee8057
@aritrachatterjee8057 5 лет назад
Thank you, Dr. Ana for making this so simple. I could not get concept at first when i was going through MIT 6.00. But now i am equipped with the understanding and assignment problem(6.00) is "walk in the park ". Thank You. May Cosmos bless you with more knowledge...
@rajeswarynarasimman3728
@rajeswarynarasimman3728 5 месяцев назад
Very helpful video indeed. Please show the slide always. Preferably, the slide and the professor together, maybe as picture in picture.
@joost3732
@joost3732 2 года назад
Ana explains all the theory very clear. Already knew most of the python she explains but it still helped me understand the big picture of programming
@theodorejonathan6460
@theodorejonathan6460 2 года назад
Same with me. She is a great. Feminine power
@peasant7214
@peasant7214 2 года назад
@@theodorejonathan6460 ?
@theodorejonathan6460
@theodorejonathan6460 2 года назад
@@peasant7214 Hi!
@woltron4o
@woltron4o 6 лет назад
I like this lectures. High level of education. Thanks :)
@btvaalburg
@btvaalburg 4 года назад
This prof is amazing!
@sapphirelovespj
@sapphirelovespj 6 лет назад
When she's talking about the contents on the projector screen, can you show more of the screen?
@Noldy__
@Noldy__ 6 лет назад
Click on the link in the description. The lecture pdfs are there and you can use them to follow along.
@MrFaiqueShakil
@MrFaiqueShakil 4 года назад
So much concept in this lecture.
@hamids4550
@hamids4550 6 лет назад
camera needs to focus more on the board so we can see what she's talking about rather than just seeing her without the content. It's annoying sometimes
@Noldy__
@Noldy__ 6 лет назад
Click on the link in the description. The lecture pdfs are there and you can use them to follow along.
@tripleplay4
@tripleplay4 6 лет назад
Yes but we can't see what she is drawing or pointing at in that case. Camera should at a minimum be on the slides when she is looking at the slides.
@bee_irl
@bee_irl 3 года назад
@@tripleplay4 She is pointing with a laser pointer usually. For us to be able to see that, there would need to be a second camera that focuses only on the board (it would be too much movement for this single camera), and even then, we could barely see the laser dot. I don't find it very hard to follow along on the pdf.
@CrushOfSiel
@CrushOfSiel 2 года назад
Darn, a lot of this information would have been great to do the hangman assignment! I did it all with strings and it was a bit challenging and probably hard for another programmer to follow in some areas. Lists are awesome.
@akshayalva3879
@akshayalva3879 2 года назад
yeah man, I'm still trying to do that, as I'm watching this vid
@peasant7214
@peasant7214 2 года назад
well I used ' '.join function at the assignment before I watch this lecture
@loptrfawkes2149
@loptrfawkes2149 Год назад
I'll make a comment on it, since for some reason this really confused me: why .sort() returns none. (If I get something wrong, feel free to correct me and I will edit this comment, I am new to coding.) The reason that list.sort() and list.reverse() return None, while sorted(list) returns a list's values, is basically that the methods are completed by different means. Code that returns None is completed "in-place," which means that the original variable itself is not duplicated, only changed. Python does not want you to think that a new variable has been/could be created after running the method .sort() or .reverse() (or any other in-place method), and so it returns None. It is basically telling you that any method that is done in-place CANNOT generate a new variable because it has not duplicated the old variable. Meanwhile, sorted(list) is creating a new list entirely, and so you can assign it to a new variable name. ( sortedList = sorted(originalList) ) So basically, don't assign in-place methods to any new variables.
@nancylu4049
@nancylu4049 3 года назад
Wonderful! learned a lot! (It would be great if the camera man focused on the slides when Dr.Bell was pointing at them.)
@russellfatemi4616
@russellfatemi4616 2 года назад
Thank you professor Bell
@911Dagur
@911Dagur 6 лет назад
I love that you put these lectures out for everyone to see. But wouldnt it be better to be able to see what the professor is pointing at on the slides? Makes it hard to understand what she is talking about when you can't see what she is referring to.
@InventTwig
@InventTwig 6 лет назад
visit the ocw website for the ppts
@yovelavitan8854
@yovelavitan8854 5 лет назад
on the last problem you can search l2 instead of l1 as shown below: def k(l1,l2): for n in l2: While( n in l1): l1.remove(n)
@jhw8685
@jhw8685 5 лет назад
u cant look into l2 and remove from l1 instead. the remove function only removes the first occurrence of the element n in the list, not all element n. l1 = [1, 1, 2, 3, 4] l2 = [1, 7, 9, 7, 0] u will end up with l1 being [1, 2, 3, 4] and l2 stays as [1, 7, 9, 7, 0] and there is still a duplicate
@yovelavitan8854
@yovelavitan8854 5 лет назад
@@jhw8685 thank you for the correction, I now changed the code above and I think it's correct now
@kamranasif212
@kamranasif212 6 лет назад
Very informative
@imas1239
@imas1239 3 года назад
I ( we ) need a course from u just to define all these different words you use in most of ur analysis? ???
@Pkmafffy
@Pkmafffy 6 лет назад
I have two questions: 1. How do I create a tuple, e.g. ((1, a) (2, b) (3, c)), without manually inputting values? 2. I can't figure out how to return an updated list from a function. Every time said function takes in a new input, all old values of local variables are forgotten and a new list is returned instead of an updated one. These questions are in regard to problem sheet 2 - Hangman. Any advice would be greatly appreciated!
@EgeOnatDoguslu
@EgeOnatDoguslu 6 лет назад
github.com/egeonatdoguslu/MIT-Assignments/blob/Hangman/Hangman I completed the assignment. It might not be the most efficient one for now but, its working. Im sharing that it could give you some clue.
@Saganist420
@Saganist420 6 лет назад
I really love her subtle humor.
@lanhaibibolanhaibibo1461
@lanhaibibolanhaibibo1461 7 лет назад
great lecture. Was just wondering, which software do you use to create the lecture slides?
@draftingsavant7190
@draftingsavant7190 7 лет назад
lanhaibibo lanhaibibo powerpoint
@lanhaibibolanhaibibo1461
@lanhaibibolanhaibibo1461 7 лет назад
@drafting savant, Which trick is it called in using powerpoint? Is it possible to do it using latex?
@manuelignacioperezcarrasco6311
I think it's Beamer, a latex tool to create slides.
@infinitasfish5499
@infinitasfish5499 2 года назад
Thank You very much!
@jetspray3
@jetspray3 4 года назад
The camera focus screwed up the whole thing but even though the doctor is good at teaching.
@yongshengtay8016
@yongshengtay8016 2 года назад
Comparing the current course available on edx and this, I still prefer the full lecture length videos from Fall '16. It's a lot more compact but it's easier to stay focused.
@vidieo__
@vidieo__ 2 года назад
ikr. i tried the edx course but i honestly still prefer a recording of an actual classroom! the only downside is that you don't know how well you do on the problem sets.
3 года назад
29:25 sort list and reverse list
@UnmannedsRandomStuff
@UnmannedsRandomStuff Год назад
no idea what is going on when using laser pointer to point at the physical screen where couldn't see in this video.
@edderiofer
@edderiofer 3 года назад
In that last example, couldn't one iterate through the list backwards?
3 года назад
5:28 what are they useful for
@Neil.Menezes
@Neil.Menezes 7 месяцев назад
Loved the Photo of Justin Bieber being credited to © Justin Bieber in the end 😂
3 года назад
22:00 .extend, concatenate, delete, remove, etc...
@briannestor5125
@briannestor5125 6 лет назад
I am curious as to the advantage of using a tuple over a list. It seems as though lists have the exact same functionality as tuples but with the added advantage of you being able to modify them(mutability) if you so choose to. Why not just alway use lists?
@rhodesclosed9563
@rhodesclosed9563 6 лет назад
I believe lists use more system memory
@raphaelcrespo3725
@raphaelcrespo3725 5 лет назад
it an option for a 'list' that you wanna make sure that doesn't change along the code.
@geethabr374
@geethabr374 5 лет назад
Because lists may change while code execution and cause unintended output generation. But tuples never modify and that is the added advantage.
@kobbyfynn8043
@kobbyfynn8043 3 года назад
Since lists are mutable, they cant be used as keys in a dictionary, but tuples can. So that's one reason to use tuples over lists sometimes
@liza10o
@liza10o 4 года назад
What does that \ do after max year?
@RyanScarbrough
@RyanScarbrough Год назад
Thanks for this! Mutable side effects are annoying! x_x
@dhruv_aditya
@dhruv_aditya 2 года назад
Thank you mit open course to provide us wonderful lectures . 🇺🇸 ❤ 🇮🇳
3 года назад
0:45 recap functions
@devkiosk
@devkiosk 6 лет назад
What is the difference between the extend and append functions?
@nahfid2003
@nahfid2003 6 лет назад
search on google, it's a popular question
@geethabr374
@geethabr374 5 лет назад
Append can add only one element at the end of a list while extend can add multiple elements to an existing list. When you try to add a list at the end of a list using append, it creates ONE element which is again a list and adds it to the list. But extend considers each element like a separate entity and adds it to the list.
@HealthyFoodBae_
@HealthyFoodBae_ 3 года назад
Thanks
@senanurarslan2323
@senanurarslan2323 5 лет назад
i wish i could see the slide
@deeptadevkota5106
@deeptadevkota5106 4 года назад
You can download the slides using the link provided in the description.
@RamkrishanYT
@RamkrishanYT 7 лет назад
lol ...when she says she's being modest about Justin
@zcodingkid4749
@zcodingkid4749 Год назад
at 19:19 a list was not created yet. Can someone explain how this works
3 года назад
15:00 inmutable and mutable
@utkarsh22smart
@utkarsh22smart 4 года назад
What is the difference between append and extend of the list.
@ficklampa1
@ficklampa1 4 года назад
L = [0,1,2,3,4] L.append( [101,102,103] ) L = [0,1,2,3,4, [101,102,103] ) L[5] is [101,102,103] L = [0,1,2,3,4] L.extend( [101,102,103] ) L = [0,1,2,3,4,101,102,103) L[5] is 101
3 года назад
2:37 how to represent a tuple
@najsh2
@najsh2 2 года назад
For the last L1, L2 question, I've tried it with the first code but got L1 = [2, 3]. Is that because Python has been updated to fix that issue??
@wilcohermens3492
@wilcohermens3492 2 года назад
Tried the code myself, it didn't work. Maybe you have changed the order of the list? Or did you assign a new list and didn't rerun the code with the original list? Besides that, python has a more simple way to remove the duplicates, try the following: L1=[1,2,3,4] L2=[1,2,5,6] L1=[ e for e in L1 if e not in L2] print(L1)
@techcorp
@techcorp 5 лет назад
Bad editing. Makes watching this otherwise wonderful lecture a grind.
@unloadinggnat3396
@unloadinggnat3396 4 года назад
13:25 Who is Joe
@peterlin2352
@peterlin2352 4 года назад
i have no problem with the camera focus. I think it is great to point to the speaker for her great presentation skill. A good skill to learn for me.
@markmilan57
@markmilan57 8 месяцев назад
I thought python runs from up to down. Your lists mutability shows down to up.
@Alikhan-ee7bs
@Alikhan-ee7bs 5 лет назад
very helpful Could you share the code link and the PPT slide for such kind of code?
@mitocw
@mitocw 5 лет назад
Code snippets and lecture notes are available on MIT OpenCourseWare at: ocw.mit.edu/6-0001F16. Best wishes on your studies!
@KrishnaDasPC
@KrishnaDasPC 5 лет назад
I have started a new github site with the code snippets which is currently work in progress. you can have the running examples for the Video 3 here pckrishnadas88.github.io/MIT-6.0001-Introduction-to-Computer-Science-and-Programming-in-Python-Fall-2016/#/ch03/README
@junfan02
@junfan02 2 года назад
I have a confusion, If tuples are immutable how does nums = nums + (t[0],) work?
@SameAsAnyOtherStranger
@SameAsAnyOtherStranger 2 года назад
Not sure what context you would use that in, but zero value listed tuples are asking for a return of "false" because that's a boolean if/or/else statement.
@avernvrey7422
@avernvrey7422 Год назад
it's concatenating an empty tuple to a singleton tuple (and on and on as the for loop runs). Consider; nums = 'walk' nums = nums + 'ing' print(nums) will output walking. 'Walk' and 'ing' are immutable as strings, but they can be concatenated together. In the same way a tuple can be concatenated to a tuple. nums = (1,2) nums = nums + (3,4) print(nums) will output (1, 2, 3, 4) What it's not doing is changing an element within a tuple, as tuples are immutable.
@peterhind
@peterhind Месяц назад
Tuples are immutable, meaning once they are created, their contents cannot be changed. However, you can create a new tuple by concatenating existing tuples together. This doesn't modify the original tuples but rather creates a new tuple containing elements from both.
3 года назад
1:40 tuples
@aghaaslam9575
@aghaaslam9575 3 года назад
It would be better if the Slide and the lecturer are split in a video
@user-sj4rg2xi1q
@user-sj4rg2xi1q 6 месяцев назад
I found something wrong which q=0 is right but the r = 4 is not true .
@obli8984
@obli8984 2 года назад
Obli is getting progress
@brainstormingsharing1309
@brainstormingsharing1309 3 года назад
👍👍👍👍👍
@yusufmohammed4452
@yusufmohammed4452 3 года назад
That's the only thing I don't like about these videos...when the professor is calling attention to something on the board the camera person just keeps staring at the professor. Can we see what's she's referring to? It's kinda frustrating.
@bactran9724
@bactran9724 2 года назад
so Python knows to map min_n and max_n to min_year and max_year....?
@avernvrey7422
@avernvrey7422 Год назад
as long as the order is correct to what you want. The variable names don't matter, it's the order that matters.
@quocvu9847
@quocvu9847 Год назад
10:43
@kumar_vivek764
@kumar_vivek764 2 месяца назад
12:38
@PasangWangdi
@PasangWangdi 3 года назад
MIT need some camera training
@hossainurrahman6700
@hossainurrahman6700 2 года назад
Mam is very beautiful
@jyvben1520
@jyvben1520 10 месяцев назад
Sadly we never see where she is pointing to, makes it a bit more difficult to follow, showing her waiving her arm is useless. Hope the latest videos produced by MIT fix this (if any), maybe some bright spark can solve it or solved it. And give her some rubber bands to keep her shirt sleeves up ?
@algemmegla9002
@algemmegla9002 3 года назад
Regarding: 39:56 Two lists, remove same value - Mutation and Iteration. Just thought I would share what I did: def remove_dups(L1, L2): L1_copy = L1[:] # Make a copy of L1 first, or iteration gets messed up. for e in L1_copy: if e in L2: L1.remove(e) print("iteration:", e, "list:", L1) # Prints each iteration number, along with the list. L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) #--------------------------------------------------- print("", "-" * 30, "") # Puts a space/line/space between the two outputs. def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) print("iteration:", e, "list:", L1) # Prints each iteration number, along with the list. L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) #------------------------------------------------------------------------------------------- ''' Output (you can see where it skips the second iteration): iteration: 1 list: [2, 3, 4] iteration: 2 list: [3, 4] iteration: 3 list: [3, 4] iteration: 4 list: [3, 4] - iteration: 1 list: [2, 3, 4] iteration: 3 list: [2, 3, 4] iteration: 4 list: [2, 3, 4] '''
@rockren8236
@rockren8236 8 месяцев назад
The lecture is great, but the camera man should be fired. 10:47 Show us what professor is pointing at!!! OMG!
@vigneshr9577
@vigneshr9577 5 лет назад
Functions and methods are same, isn't it?........
@kirankalyan5674
@kirankalyan5674 5 лет назад
Vignesh Prasanth yep they are 👍
@geethabr374
@geethabr374 5 лет назад
No, they are not. Functions are generic. On the other hand, methods are functions that can only work with a specific data type. For example len( ) is a function because it can work on all the series type of data types like strings, tuples, lists. But append( ) is a method because it can only be used with list.
@DarkellVein
@DarkellVein 2 года назад
So, if you make a variable, equal to another variable, you are creating an alias. So, if var1 = var2, then var1 points to the same memory address as var2, making it a pointer to var2. Coming from c++ it seems weird that when assigning var1 to var2, it makes a pointer, instead of a copy. And instead, having to specify when do you want a copy... But it's ok, as python's thing is being syntactically simple and it also reduces the garbage to collect, etc, etc.
@norgileatmonseaur6698
@norgileatmonseaur6698 3 года назад
Ah yes, when a concept is being explained the logical course of action is to quickly cut away from the slides.
@gr8b8m85
@gr8b8m85 4 года назад
And this is why university is better than random youtube videos.
@craigdanielmaceacher
@craigdanielmaceacher 3 года назад
FYI don’t use capital “L” as a name, or capital L for anything in python code, it’s not idiomatic python, use a more descriptive name, and avoid capital letters, especially single capital letters. I understand why they did it though, for an example you don’t need a long name and lowercase “l” is hard to discern from the number 1 with a lot of fonts. Get yourself a monospaced programming font like Hack to help!
@beeilve
@beeilve 5 лет назад
I feel like she didn't explain aliasing, mutability or cloning clearly.
@geethabr374
@geethabr374 5 лет назад
Refer to John V Guttag's text book. She's using the same and concepts are clearly and concisely explained in the book.
@keqi2892
@keqi2892 4 года назад
Why Dr.Bell always wears the same clothes every-course?
@47moris
@47moris 4 года назад
kein zhou hahaha
@MrFaiqueShakil
@MrFaiqueShakil 4 года назад
it doesn't matter.
@bikashsubedi2863
@bikashsubedi2863 2 года назад
this video introduced Justin Bieber to me
@fwily2580
@fwily2580 2 года назад
So why would I pay a ton of money for this?
@airbornez602
@airbornez602 3 месяца назад
Camera man is an BIG L
@buntyyadav7781
@buntyyadav7781 Год назад
Bad way to learn programming...
Далее
Tuples
3:29
Просмотров 57 тыс.
Python lists, sets, and tuples explained 🍍
15:06
Просмотров 212 тыс.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
the TRUTH about C++ (is it worth your time?)
3:17
Просмотров 568 тыс.
Immutable vs Mutable Objects in Python
9:55
Просмотров 62 тыс.
Data Types in Python | Python for Beginners
21:58
Просмотров 82 тыс.
For Loops With Strings
4:19
Просмотров 61 тыс.
Mutable vs Immutable - Python
21:21
Просмотров 19 тыс.
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
1:27:46