 Welcome back in this video and the next couple of videos We are going to talk about sequential data. This is chapter 7 in the book So in this first video of the series We are going to talk about sequential data in abstract terms so to say so we are going to review four properties that we have seen before in the video where we compared abstract data types versus concrete data types and Review for properties that every sequence so to say has so to do that. Let's Create a new notebook and Simply rename it into sequences So let me give you two examples of a sequence the first one is going to be simply a list of numbers and As we do in this course many times Let's simply take the list of numbers from 10 through 12 this time are provided to you in order. Usually we do that well with random order But here the numbers are provided in order and it's also create a second object which I call text and There's a simply going to be a text. Let's say lorem ipsum and I think it is so long the law sit on me it Okay, so the question now is what to do these two objects have in common So first of all know that both have a different data type so in memory they will look different So if I ask the Python to build in a type function And I call it once for numbers and I call it once for text then what we Get is we get the answer that number is a list object and the text is a string object Okay, so what is the commonality so the commonality is that both are sequences? Okay, so let's write that down both so-called sequences and Sequences are a special breed of a so-called collection and a collection is also a term just like sequences that is formalized in the Python documentation So let's also write that down sequences a special version of Collections so let's review the properties. So the first property we are going to review is the so-called Container property. So let's make this a header maybe so the container property and The container property simply means an object in abstract terms contains references to other objects So how can we see that with with the numbers and text example? Well, we can see that by using the in operator so let's go ahead and check if the number zero is in numbers and It is not that we get back the false as the answer here The more important thing is that the in operator works with numbers as the right operand and in the similar spirit We can go ahead and check if The letter O is in the text and this also works and this time we get back true So the answer true or false is not the important thing here the important thing is that the in operator itself works so I give you an example of Where the of a situation where the in operator does not work. So let's say let's go ahead and Maybe take the number 333 and The number consists of three digits so to say and we could ask question Is the dirt is the digit three in the number? 333 and to us humans we would say yes, but in this case to Python it the question doesn't make sense So this is why we see a type error. So in other words the in operator does not work with the integer data type So in other words the integer data type does not have the container property Okay, but the list data type and the string data type they have So you may wonder How can I come up with these terms and I told you earlier that these terms are formalized in the in the documentation There's an another way of how to look up these names or how to see that the names must be correct From the standard library. Let's go ahead and import from the collections module the so-called ABC sub module from from the collection collection module and let's Import it as simply ABC. Okay. ABC stands for abstract base class In other words, this is basically the fancy term for an abstract data type And there are a couple of them that are defined on the ABC object here One of them is going to be the container property. So let's go ahead and we see that Container indeed is a class. So class we will see in chapter 10 Which is a bit advanced but a class is basically a blueprint for how to construct objects of this data type And we have seen classes before that the the built-in classes like int and list. They're also the what we called the constructor functions This was basically The two sides of the same coin here. So what can we do with the container ABC the container abstract base class? Well, the only thing that we could really do is we could use python is instance function is instance And we could check if numbers which is a list is also So let's go ahead and check if numbers is a list python tells me yes numbers is a list It is an instance of a list But also instead of using a concrete data type here What we could do is we could use the abstract data type. So let's go ahead and ask if numbers Is a container in abstract terms and the answer is true as well Okay, and the same of course holds true For the text object So if I ask python hay is text the object the string object also a container Then python will confirm to me. Yes, it is a container and just to illustrate the the point that for the digit 300 For the number 333 we get a type error here We could of course also go ahead and ask the question Is the number 333 also a container And the answer is in this In this case false. So a true here means the in operator is supported a false here means the in operator is not supported So there's a one to one correspondence so usually When programming you don't see um use you don't see the abc module here are used that often Okay, it is a bit of an abstract thing and there are Cases where we want to use it but for a beginner It is not so important to understand the abc module here I'm just illustrating here that you see that the terms I come up with They actually exist somewhere in the in the core of python in this in in this case in the standard library Okay, so that is one property the container property, but there are a couple of more properties So another important property which we already also saw in the video abstract data types versus concrete data types is the property Of we call it sized And the size property simply means does the object contain a finite number of references So we have we are a container um here because we are we contain references to other objects But now the question is Uh, is the number of references to other objects? Is it finite or is it infinite? And the answer is if an object is a so-called sized object then the number is finite, of course And what does that mean when coding? Well for coding purposes This means that the object supports being used as the argument to the lend built-in function Okay, so if I call the lend function and I pass to it numbers Um, I get get back 12 which is the number of numbers in the numbers list here if I go ahead and um Call the lend function and I pass it text. I get back 27. Why 27? Well 27 is the number of characters in the text object here. Okay, the number of uh, Unicode characters to be precise Now let's go ahead and also Call the lend function and it's passed to it the number 333 So we could imagine that we as humans when we view a number with three digits Then we could think of the length of the number to be three for example because it has three digits in it, right? So if I execute this I get a type error again And what we learn from that is that um, the integer data type is also not a sized data type Okay, so the integer data type is neither a container nor a size data type But both the numbers and the text objects so the the list and the string objects They are both container and sized data types So it doesn't stop here So what I'm not doing here is I'm not doing the example with the abc module here for the sized Thing here for the size property, but this could also be done But let's simply go ahead to two more properties So the third property Is what we simply refer to as the iterable property And the iterable property simply means we can loop over an object So let's try that out Let's loop over the numbers list and we already know that this works because in the very first example of this course We already looped over a list. So we know that this has to work So I simply go ahead and say four number in numbers So I'm using numbers the list object as the target over which I'm looping And let's do something very simple. Let's say print Let's say number Let's square it and let's also print everything On one line and now we have the square numbers from one to twelve Okay, quite simple But the the important idea is we can loop over the numbers object and therefore the numbers object is iterable Now let's do the same exercise with the text object And as we already saw in the previous videos where we talked about the string data type in detail We can also loop over the text object here. So we can say for character in text And let's simply say print character And let's simply put One space in between all the characters and then we get the same sentence printed out But there is a space in between every character Okay, so um the important idea here is not that we can loop over them But the important idea is that or that we The important idea is not that the list and the text or in the string object Define looping on their own so to say but the The big idea is that both share the commonality both share the same behavior in this regard and we call it the iterable behavior And if we do that with the number 333 so if I say for for example for digit in 333 print digit I am also simply going to get a type error because a in data type again is not iterable here Okay, so Why are these three properties so important? So container sized and iterable because they make up um the term collection or the let's call it the matter the matter Property of a collection. So let's write that down here in parentheses First three properties That is what a collection is. Okay, and now every collection that also has one more property is what we call a sequence And this fourth property that is so important we can Use the formal name, but we can also Use an easier name so the formal name would be reversible And the easier way would simply be ordered So a data type that models some order so in other words the numbers in the list are ordered but also the characters in the string are ordered That is what we refer to as a reversible data type and reversible is just a fancy name here because if something can be reversed It has to have a forward order to begin with otherwise we couldn't reverse it, right? So let's drive it out right rather quickly and let's simply copy paste the for loop from above And one way to check if something is reversible is to simply Use it as the argument to the reversed built in So if I say for number in reverse numbers, I get the the square numbers in reverse order and of course If we do that for the string object as well We will see that this also works Okay, and all the objects in python all data types in python that Support all the four properties here are what we call sequences and sequences are in particular valuable When we want to model sequential data And now you may wonder why do I um focus so much on on sequence sequences and the four properties. Well the reason is Almost a lot of the data that we as business people work with In data science for example are sequential data. So whenever you open an excel file or ccv file, that is sequential data Okay, vectors are sequential data matrices are sequential data And a lot a lot more other things. So all the data that you typically store in an sql database They can be viewed as a sequential Data set and so on so everything we are going to learn in this big chapter in chapter 7 That talks about sequential data in in general This will fulfill these four properties and you can always relate it into your head to basically working with excel-like data In in a programming language Okay, so this this video here is basically a review or a focused video Continuing from the abstract versus concrete data types video earlier in the course And here we are focusing in particular on sequential data Now you understood everything you need to know in generic terms about sequential data and again You could check it in code using the abc module But as a beginner you probably won't need that too often, but long term In the long term basis, I think it's very valuable to also look into the abc module other than that simply Know the four properties and the big reason why you as a beginner should know these four properties is If we go into the python documentation, so let's for example Go into the library reference and into the page that we have so far seen the most the built-in functions page If I go ahead and look for let's say iterable, we will find it very very often And now you know what that means iterable is simply any object over which we can loop It can be a list, but it can also be a string We don't care any object that we can loop over in abstract terms And also the term sequence you will find very often So if you look for seq you get 28 search hits here So knowing these terms is not only valuable for theory for theory But it's also valuable for read for learning how to read documentation And when you can do that when you learn how to read the documentation efficiently Then you will become a good programmer quite soon So I will see you in the next video when we talk about the list data type. See you then