So this is a classic error. I've not made a copy of the list. I've got an alias of the list.
这是个相当经典的错误,在这里我并没有得到数组的。
I've thrown away most of the array- most of the list, I shouldn't say array- most of the list. All right?
我已经把数组的大部分都排除了-,列表的大部分-,我不应该说数组-列表的大部分?
If you ever try to go beyond the boundaries of an array, as we'll soon see, bad things happen.
如果你试着超出了数组的界限,我们将看到,会发生坏事情。
It is going to give me back a tuple a collection of two things, and so check out the syntax.
它将给我返回一个数组或者系列的一对值,然后检查一下语法。
I've written a little for loop, which is going to iterate over all of the elements in the list.
让我们先看看这儿的代码,我已经写了一个循环语句,用来迭代处理数组中所有的元素。
Yeah, it's kind of simple, but it gives me an ordered list of these things, And let's run it. OK.
让我们来运行运行吧,好,我会先去搜索一些数组中没有的元素,让我来试试,看-1在不在这个数组里。
And if I'm walking down the list, this is probably order of the length of the list s because I'm looking at each element once.
这可能大概就是数组的长度,因为我会遍历数组中的每个元素一次,现在你可能会想,等等,数组已经排好序了。
If I had lists of lists of lists, then it would only take out the first level of it.
贴到另外一个数组的后面,它当然是实现了套数组的操作。
And we're having a difference of opinion as to whether we should use a tuple or a list here, right?
可以“是结果,明白了吗?我们队在这里是应该用数组,还是链表还有一些不同意见对吧?
When you are searching a list to see whether it has an element, you don't randomly probe the list, hoping to find whether or not it's there.
当我们在一个数组中,寻找目标元素的时候,我们不会随机的调查数组来看。
So the first thing we'll do is, we'll print the element, in this case it will be a list right? Because it's a list with two lists in it.
因此这儿我们要做的第一件事,就是要显示元素,在这儿元素就是数组了对不对?,因为这个数组包含了两个数组。
That's just a graphical incarnation of this thing called an array and notice, the games can, in fact, interact with a human much like Wednesday, I'm leaving my house.
它其实是数组变量的,图形化,具体化,这个游戏实际上是与人交互的,如周三看到的,我正要离开我的房子。
These are sort of the cells, if you like, in memory that are holding the elements of the list.
记忆就像是数组中的元素,我们之前说的是,我在这里开始并且比较。
And again, this points out something I wanted to me-- I mentioned last time, list can be heterogeneous, in the sense that the elements can be multiple different types.
这儿又指出了一点我想要告诉大家的,我上节课也提到了,就是数组是多相的,也就是说元素可以是多种类型的。
I'm going to print it and let's see what it prints.
我要将其打出来,我想显示下数组的内容。
And then, when I got- I'm also going to count how many comparisons I do, just so I can see how much work I do here, and then notice what it does.
并能看到算法干了些什么-,然后是如果这个索引,比数组的大小小的话,就意味着还没检索到数组的最后。
In fact it gives me back, now I hate this, it's actually a list it's not a tuple. But for now think of it as giving you back an explicit version of that representation of all those elements.
它实际上是一个数组而不是一个元组,但是现在你们可以把它认为,是明确的这些,元素的一个表示,你会在接下来的一些课程中看到。
Remember what range does, it gives me a set or a collection or a tuple of integers from 0 up to 1 - is the last value, so it's going to give me everything from 0 up to the total number of heads.
我将要在这个循环范围内加上鸡的数量,记住循环范围的目的,它给了我一个从一开始的整数集合,或者数组,这是最后的值。
All right? If I'm gambling, I'm saying, gee, if I'm really lucky, it'll be only on this side, and I've got a little bit of work to do, but if I'm unlucky, I'm scrawed, the past pluperfect of screwed, OK., or a Boston fish.
如果我够幸运的话,目标数就会在这边的,这会大大减少我的工作量,但如果不幸运呢?我就完蛋了,我就得再从剩下的这么大的数组里找了,这很痛苦,因此选中位数是正确答案。
But if, at any point, I get to a place in the list where the thing I'm looking for is smaller than the element in the list, I know everything else in the rest of the list has to be bigger than that, I don't have to bother looking anymore.
比当前位置数组的元素要小,我也就知道后面的数肯定,也都比我的目标数要大了,我就不用再继续进行下去了,这意味着目标数不在这个数组中,我就可以退出了。
If it's there, I'm done, if not, I keep walking down, and I only stop when I get to a place where the element I'm looking for is smaller than the value in the list., in which case I know the rest of this is too big and I can stop.
并且保持遍历,我只在当当前位置的数组元素,大于目标数时停止,这意味着剩下的元素都比目标元素大,但是其他的情况,我还是要遍历完整个数组。
Didn't create a new list. The old l is still there but it's different than it used to be.
它改变了数组,而并没有新建一个数组,老数组l依旧存在。
And we're going to start with one that you many of you, have already bumped into perhaps by accident, which are lists.
曾经遇到过的,可能是偶然遇到的类型来开始,就是数组,数组和字符串类型。
Constant. Ooh, constant says, no matter what the length of the list is, I'm going to take the same amount of time.
这个算法用的时间是相同的,我不这么认为,如果我们创建一个十倍于以前大小的数组。
Second step, hm. That also looks constant, you think? Oh but wait a minute. I'm accessing s.
第二步,恩,看起来也像常量,你认为呢?等等,我在进入这个数组。
You have nothing that identifies that there, you have no way of saying what this grouping actually means.
我仅仅用了一个数组,就把信息聚集到一起了,假设我给了你。
I shouldn't say list, those two tuples, and walk through them to find the pieces that match up.
除数数组进行对比,我不该说数组的,是元组,遍历这两个元组找到相同的元素。
You're gonna have to be a little more careful when it comes to adding stuff to an array and removing it from.
当你向数组里面添加东西或者从中取出东西时,要非常非常的小心。
It's going to take this list and add to it something else.
这个代码有什么作用呢?,我将会把一些东西加到这个数组里面去。
And in that case, in general lists, I need to figure out what's the access time.
一些浮点数,一些字符串,一些数组内部的数组,各种各样。
应用推荐