Chủ Nhật, 31 tháng 12, 2017

Auto news on Youtube Dec 31 2017

This Record Is Available For Informational Purposes Only!

For more infomation >> Утиные Истории. Крупным Планом. Моя Видео Охота (Digital Max Cinema) - Duration: 3:11.

-------------------------------------------

Retailers Making Major Changes In The Digital Age - Duration: 4:14.

For more infomation >> Retailers Making Major Changes In The Digital Age - Duration: 4:14.

-------------------------------------------

Digital World - Sequences and Lists - Duration: 3:40.

The above hyperlink is a textbook on Python, and this is the section it comes from

Sequences are 'ordered collection of values'

You can have lists like [1, 'abc', 2.0] etc where the types are different.

Lists are created like this: subjects (or any name you give) = ['element', element, element]

Lists in Python start from 0, so the first element in a list is subjects[0]

We can also index using negative numbers

As seen here, we have the list with the label of subjects

We have Introduction to Design as the first element

When we wish to return the first element, we type in subjects[0]

Then, when we wish to access a certain value, we make use of the function len to find the length of the list

And when we access the element of the list backwards, such as HASS, we count backwards using a negative number

If we were to use the plus sign, we can connect our original list with another list

Here, we have used subjects and added HASS 2 and Chem and Bio

But since we have not mutated our current list, when we call subjects again, we return our 4 element list

We can also return boolean values. So we have a team of three Pokemon

Obviously, the number of elements here is 3, so calling upon len will return 3 elements.

But since Meowth is not in the list, it will return False. Pikachu, being in the list, will return true.

We will be moving on to Slicing and Indexing. This creates a new list rather than mutating the original list.

Say we want to access more than one element of a list, we use a slice. We indicate using a starting index and an ending index, separating by a colon.

If we want a second copy, then we can choose to use a [:] to get an exact copy of the list

But say you want a partial copy instead of the entire list

Of course, there are certain rules that can be applied as shown below.

If the step size is left out, the default step size is 1. So your last gap, which is optional, can be used to indicate the step size as seen in directors[0:4:2]

If your starting index is left out, it is automatically assumed that you are starting from the beginning index, that is zero.

Same goes for the ending index: if there is no ending index specified, then you go to the end of the list

For a Python list, say in directors[1:3], you start from the second element, that is to say, directors[1] which is 'spielberg', and you return elements 1 and 2. 'spelberg' and 'bigelow'

But since the fourth element is where you stop, you do not return directors[3]

Remember that since each time you are returning a list, you are not mutating a list, so for every instance of slicing, your original list remains unchanged

If you were to look at your step size, if negative, the order of the list would be going backwards. Here, the first and last element of your sliced list is left blank.

But your step size is -1, so you return your sliced list in reversed order to your original list

Now we shall move on to list comprehension. It's a short form, designed to make your code neater. The format is as shown here.

You have your map expression, for i, i being your element, in your list. You can choose to use a filter for greater discrimination

i+1 is what I am doing to the elements that fulfill the filter expression. Since I am adding 1 to each of the elements that fulfill the filter expression

I have 1, 3, 5 and then add 1 to each of these elements, since i here is not the indice but the element itself.

So you keep your filter expression, and then you create a new list using your square brackets. And since you are creating a new list, you can attach a label to this new list to continue using it.

Python allows for mutation. So since you can change your contents, you aren't restricted to mathematical operations such as + and * for changing your lists' contents.

Here, rather then adding 'onions' using a '+' sign, I use the function append.

It may not seem different now, but say you are going through a for loop. You can use append to append the element that you want.

I can add onions, pickles or whatever flavorings to the list called pizza1 without using a plus sign.

Append is twice as fast as plus. Further more, pizza1 + ['onions'] creates a new list, while pizza1+= 'onions' and pizza1.append('onions') mutate the original list

Lists and dictionaries are mutable, so in dictionaries you have dict[key] = value. Here, you can use insert, remove or append to change the contents of your list.

In list indexing, you can mutate individual elements.

So say you have a lst, with the fifth element of 'bye'. You want to change the value to 'hello'. By refering to the index of the list, you change the contents of that list as well.

One more thing: the difference between pop and remove.

Pop is basically Remove + returning the element at that index.Think of it as a stack of books. You pop out the book at that index, but instead of just removing it from the stack, you are taking out the book to read it as well.

That's all. Thanks for watching!

Không có nhận xét nào:

Đăng nhận xét