 As I mentioned, Picon Singapore is happening from June 17 to 19. This is the third time we are organizing it. These are the three keynote speakers. I am sure you guys know these people and we are actively looking for proposals for talks. So please submit a proposal as soon as possible because the deadline will end soon. So let's start. So my talk was supposed to be about tips and tricks in Python. So I want this to be an interactive session. So please stop me or please interact with me otherwise I wouldn't know whether you guys understand or not but be nice because I am also new. Okay, so how many of you? Okay, how do I... Command plus here. Is this better? Can I increase one more? Okay, so how many of you guys are familiar with the asterisk notation before the function arguments? Okay, so around half of you. So as you can see I am passing three arguments to Fung2. The asterisk notation converts the arcs to a tuple and then so just to prove and here I change the first two arguments and then I pass it back to another function x, y, z and it prints the result. So here we pass goodbye cruel and world. This is useful if you don't know how many arguments a function is going to have. It works in both Python 2 and Python 3 and then it just changes the... This was just to demonstrate that it works. It just changes the first two elements and then we print all the three elements. So both... So the arguments are getting packed and then unpacked. Okay, now this is how you call the range function normally. The 3 to 6. So range function just starts from the start value and then prints till 1 minus the final value and so you get 3, 4, 5. But you could also adjust to demonstrate that unpacking works. You could declare the arguments as a list and then you pass it to arcs and range function... So it accepts two numbers but this automatically unpacks it to 3 and 6 and so we get the same result. Please do interrupt me if I'm going fast, going slow or anything. Okay, so another example. Now this was when we were unpacking lists. Now let's see if it works for dictionaries. So here I declare a dictionary and then when you want to unpack dictionaries you put two asterisks before the dictionary name and so here the voltage is 4 million. So if you see the output, it says you have 4 million volts. It unpacks the... It matches the action key to the action... to the parameter name in the parrot function. Action to action. Voltage to... Voltage and state to state. Okay, now... Which Zen principle are we violating with this syntax? Actually, most of what I would cover, you should not use it because it makes for unreadable code. But this was... Principle number 2. Explicit is better than implicit. Yeah, and I mean this is not even the worst part. When you come to this, you should never do this. But I wanted to play around with this and so... Now the best of two, you can use it, but if you write, let's say, a math function which accepts the series of numbers, that makes sense, but if you write it and mixing arguments which are like separate... And in many cases when you don't know the number of arguments and so on, then also it makes sense. But yeah, I give no guarantees of this being good coding practices. This is just for the heck of it. So, yeah, I won't be going through... We won't have enough time to cover generators later. But anyway, this is just a generator that... If you have very large lists, then you use generators because then you don't need to store all the numbers explicitly. Like if you have a million numbers, then if you have a generator, then as you trade through the generator, the Python does not actually store all the elements in memory. So this was just an example. So it even works for generators. Here the output would be range would give 0, 1, 2. So this would be all all numbers 1, 3, and 5. And so you can unpack and unpack generators as well. Now this is sort of bested a tuple inside a list. So here again you... One way to evaluate what the output would be that you... Both on the LHS. If the LHS is not a list or the RHS is not a list, you put a list or tuple brackets here and then you simply match the arguments. Sort of like pattern matching. So A is 1, B, C is B is 2, C is 3 and D is 4. Now every Python beginner is taught that in Python it's very easy to swap variables. So if you have to swap 4 variables, then this is how your code would look like. Like that's all that is needed. I mean if you have 2 variables, then Python styles often joke that A, B is equal to B, A. And that works. But I wanted to go into how it works. So the concepts are the same. So this is a module that lets you see the sort of the bytecode. It's a module for C Python that lets you see sort of the instructions in the... Sort of the bytecode instructions. 2 is simply the line number that it is showing the instructions for. So our function has only one line. But if it had 2 lines, then there would be first be all the instructions that are executed for line 2 and then all the instructions for line 3. And C because argument is the function name. And yeah, there's only 1 line, 1, 2. So first the evaluation always starts from... So equal to is an assignment operator. So the evaluation would... It would first evaluate the right-hand side and then the left-hand side. So first it goes from left to right. So first it loads A into the stack. Load first is simply loading onto the stack. Then it loads B. Then it loads C. It loads D. Then actually it builds a tuple of these values. So this is the build tuple statement. And then it again unpacks those values. Now you would think that this is a wasteful statement because why are we building the tuple when we actually have to unpack? But if we don't build a tuple... So stack is last 10 first out. So if you don't build a tuple, then if you pop from the stack, then what you will get first is A, B. So when it builds the tuple, it first pops the elements that... It pops the elements after the last instruction. So it pops A, B, C, D, puts them in the same order in which they were inserted in the stack. It builds a tuple A, B, C, D. And then it stores the unpacked values into D, C, B, and A. So it stores the value of A and B, B and C, C and B, and D and A. Is everybody clear? If you have doubts, please ask. I am also a noob. So the build tuple and unpack sequence essentially flipped the order. Yeah, it's only because the stack is last 10 first out. But if it was smarter... Oh, yeah, I want to show that it is actually smarter. So what do you think happens here when there are only two arguments? So actually when I was reading this, then I also had the same question. I mean, why does this do these two wasteful operators? I mean, I'm sure there would be a smarter way. So actually if you see the instructions for swapping only two variables, then they are slightly different from the above. So load fast is the same because it first sees the assignment operator and then it goes to B and A. It first loads B and then it loads A. But then instead of build tuple, it actually does rod2. What rod2 does, it flips the two arguments, but it's a lot faster because it knows that the number of arguments are two and so it waste unnecessary steps in finding the number of arguments and then storing them. And so it does not have to first build the tuple and then unpack the tuple again. It simply rotates the two arguments and then puts the top value and then puts the values. So if it rotates, then your stack would read from the bottom B, A and then it would store the value of A and B and B and A. So actually this also works for A, B, C. Our next question that I had was, when does it perform these optimizations? So I looked into the C code, peephole.cs sort of the class that you should look into. I mean you can go to this link if you're interested. And then, so you see it actually has case statements for if the arguments are one, two and three. So it doesn't want to do the wasteful step of building the tuple and then unpacking it if the number of arguments is one, two or three. But still, why can you scroll up a bit? Still we can just pop from stack into the, so we can remove that line number six and put line number ten, line number seven. Why do we need to rotate them? Why don't we just pop this stack in the other way? If you remove that, then it would store the value of B and B and A and A. But in compile time, we can just switch ten and seven. We can switch ten and seven. And remove six. No, but Stoolfast does not say which element of the stack you are removing. We always remove the top element. Yes, so if you remove the top element, then the result would be same as. The same names. Yeah. A comma B would store the same values as before. So you need to know the variable. So because pattern doesn't have variables like C in the same sense, right? It's just a label. But the memory location where this A is located. So if you unpacking the same labels into different order, so you need to somehow maintain where you're reading into where you're writing. Because you don't have temporary variables like you would usually do in secret. But aren't you using the stack as a temporary variable? Actually, I didn't know about the variable part. So thank you. Is that when the stack is being used for temporary storage? Yeah. Couldn't you just plug properly on the stack and then read it back into different variables? So do you mean the variable is basically in reference? So it's pointer to the memory? Because we read from memory when we put on stack. Is there a mutual? The immutability. Yeah, this is like, I actually don't know. But this is the way the assignment works. Like the left value, right value. I have never looked at the C. Yeah, I mean actually you can go on here. I mean, I have also not investigated how exactly the loading and storage statements work. I only investigated why it doesn't have a raw 2 when it has more than 3 arguments. But yeah, we could probably look into the C code and so on. Okay, if we just look at the output of this function. Okay, yeah. So is it right to columns? What exactly is it? Is it the arguments for the command? What's in the right side? Okay, so I do not know what 0, 1, 2, and 3 are. But it probably denotes where in the stack these variables are. So it's one on top of the other. I mean, not pointers. In a stack you don't have pointers but sort of like representatives for which stack position they refer to. So this is arguments for the, so as it would be in assemble. Right side is the arguments for the command. Yes, arguments for the, not exactly but yeah, I mean it formats the output. So this is not exactly how the byte code would look like. But yeah, the analogy is correct. But I don't think that the instructions would actually have 0, 1, 2, and 3. These are just for our reference. So at which position are these values in the stack? So if we just say for example line 18 store fast 3. If you remove 12 and 15 is it? 3A and we remove 12 and 15. No, in an actual stack you will never have pointers into the stack. So these are just for a reference. So these are not actually how. This is just a visualization. Yeah, this is just a visualization. So when you actually, I mean in a stack you don't have any pointers to stack just as one pointer, the top pointer. Sure, sure. So you won't have this 3, 2, 1, and 0. So you cannot say, you can just push and pop. And then we just train pop to a pointer we want. Oh, so you are saying that instead of, so you are saying that the compiler should be smart enough that instead of popping, that instead of popping, putting them in a tuple and then assigning one by one, we should pop directly into the other label, is it? Right. I don't know the answer to this. But no, I mean, I don't think that that reasoning is correct because they're actually assigning to it. Yeah, you are actually building the tuples. So write and have a tuple. And actually you see it first builds the tuple and then it unpacks it again. So this is not exactly a tuple. This looks like the unoptimized code to me. This should not be unoptimized because this is exactly the bytecode that is produced by. I mean, I was just curious and this is why I actually used this module. So I don't think this is unoptimized code. If it was unoptimized, then then you wouldn't see the difference between this and this. Nope. Oh, good idea. Yeah, but I will go home and check it out. But yeah, true. Any more questions? Sorry, I couldn't provide the answer to this, but I try to find it. So yeah, now here I was nosy and I wanted to test different combinations. So this is simple sequence assignment. This, of course, prints 1, 2. Again, simple list or tuple, both work fine. So a is green and b is blue. Then a, b is called x, y. Whenever you see a string. So the analogies, the ways that I provide to expand the rules are not actually how they are implemented. This is just from basic understanding. So x, y, if you have a string, then you can sort of split. For your understanding, you can split it as x character comma y character. And then this makes sense because a comma b, a becomes x and b becomes y. Then if range 152, 2 is the step. So you start from 1, u plus 2. So 1 comma 3 and then u plus 5. But 5 is the end, so you cannot reach 5. So it becomes 1 comma 3. So a comma b is equal to 1 comma 3 and 1 comma 3. This example was just to show that you don't actually link tuples and lists. You can actually put generator expressions here and those will work as well. Now to nested sequences. So how you can interpret this is to make this easier to understand. Whenever you don't see, whenever you see statements like this. You can put a bracket around both the LHS and the RHS. If the LHS and the RHS don't actually have a bracket. So here you can put a bracket around a comma b. If the whiteboard was there it would be easier. So you can put a bracket around a comma b. A comma b, you can put a bracket around a b comma c. And then you can be x y comma z. So a b will have to be assigned to x y. And c will have to be assigned to z. And we already know that when we assign a b to x y. Then we get a is equal to x, b is equal to y. So a is equal to x, b is equal to y and this is z. This is the same logic just that instead of x y it's a list. For unpacking and packing you can treat lists and sequences as sort of similar lists and strings. So a will become 1, b will become 2. I mean first it will unpack this, this. So c will become this. And then a comma b will be assigned to 1 comma 2. So a becomes 1 and b becomes 2. Now these are the things that I tried and they did not work. Why? Because x, y, z would actually, I mean none of what I'm saying is actually how it's done. This is just a stools of understanding. So x, y, z would be x comma y comma z. But on the LHS we only have two values a b and c because a comma b is a nested thing. So there are too many values to unpack. So x, y, z is actually three elements. That's why it says too many values. Now here a b comma c. So actually the first step would work fine. a b will be assigned to x, c will be assigned to y. But a b cannot be assigned to x because x is just one element. So again need more than one value to unpack. That's because when it tries to assign a b, assign x to a, assign is also the wrong term. But assign x to a b, then a b, a b is two values and x is one. So this will also throw another. Now this one, again the same case. It has, because this, when you split, it's okay. The first step would work fine. There are two elements on the right-hand side, two elements on the left-hand side. a comma b will be assigned to 1 comma 2, no problem. But then when you have c and this, then actually this is, since this is a tuple, this would be split into t, h, i, s. And when you assign only c to t, h, i, s, it will not work. Because this is a tuple of only one element. While that is a string with four elements. So it throws an error, too many values to unpack because this is four values. Is everybody with me to know? Can you please go a bit slow because you are coming. Okay, sorry. So please do prompt me if I'm fast. So a comma b comma c, again it does the same thing. Oh well, this is why I should prepare my slides when in advance. This error, ignore this comment. And a comma b is assigned to x, y. c is assigned to z, so c is z. a comma b x comma y, so a b becomes x, y, z. Now this, this does not work because this is actually only two elements. And these are three elements. So you need more than two values to unpack because these are three. Now this one only works with Python 3. And I have nothing against the iPython developers. But if you have Python 2 installed, it's really not easy to get the Python 3 notebook to work. So I, so I'm using the Jupyter kernel here. But anyway, ransom side. Okay, now extended sequence unpacking. So Python 3, okay, I don't like this code because it is very unreadable. And I, but since Python 3 has implemented this feature, let's explore. So basically you see as just b, you can treat it as it can be converted to a tuple. So b can actually be a tuple. So here it's like a. So the way to solving these types of expressions is that you always evaluate the ends first. So a comma b. So b will store two comma. Yeah, here since I didn't want to copy each one in a separate cell and then space the output. So I've written less comments. A would be one. And then b would become two, three, four, five. Is this clear? Because this is actually a tuple. So if you, if you apply my evaluation rule, you put a left parenthesis here before a, you put a right parenthesis after b. And then you put a left parenthesis here, you put a left right parenthesis here. Then it says that a will be assigned to one. No problem. And then b would be b since it's a tuple. So it can be assigned to two, three, four, five can be assigned to multiple values because b is the here. We come back to the packing and packing. I hope you remember this from maybe 15 minutes ago. So yeah, a is one, b is two, three, four, five. Okay. Here again, not how it actually works, but apply the argument apply. I mean, this may be how it actually works. I mean, I didn't look at the code, but b will be assigned to five. You always evaluate the ends first and then a will store one, two, three, four. Okay. Again, evaluate ends first a one, c five, b two, three, four. Okay. Now to show that it works with characters. Again, b is a tuple. I mean, it's not a tuple, but analogously it's a tuple. So b can have zero values. So you apply a, a becomes x, b is an empty list, right? Then you apply here, evaluate ends first, b becomes x, a is an empty list. Here apply ends first, a becomes x, c becomes y, b is an empty list. Apply ends first, a becomes x, c becomes y. Now you are left with dot, comma, dot, comma, dot. b can store, b can store a tuple or a list. So yeah, so it becomes dot, comma, dot, comma, dot. Okay. Now here, a, comma, this one, again, you, if it doesn't have parenthesis around, to understand you can put parenthesis around. So a, comma, b can be assigned to one, a can be assigned to one, b can be assigned to two. Now when it comes to asterisk c, it can be assigned to bracket, bracket, left bracket, three bracket. It can be assigned to, okay, I'll just write it down here. Is this clear or do I need to explain more? Anyone who doesn't understand this? Maybe you are feeling shy as to always more of a time. So you can treat this as a, comma, b, comma, asterisk c is equal to, then a becomes one, three elements, three elements. They all map out, b becomes two, asterisk c becomes three. So asterisk c can be c. So c is equal to three. No. Oh, wait, wait, asterisk c is equal to three. So yeah, c, yeah, I got carried away. Should not put back in two minutes. Asterisk c, so actually c becomes, yeah, just to put the result same as whatever. Then a, comma, b, comma, c, comma, asterisk c, same thing. d can be empty. So d is empty here. Okay. Now I tried with this, but this, okay, Python does not allow two star expressions in the same statement. By same statement, they mean at the same level. Later on, I'll show you two star expressions in the same statement, but at different levels of nesting. Okay. Now here, a, comma, b, comma, c, two elements. We all map out, a gets assigned to one, b to two, c to this. Okay. Here. So notice the, here, a, comma, b will be assigned to one, comma, two, a becomes one, b is equal to two. Now, asterisk c, c is at this on the other side, but since c can take a sequence, so it gets assigned to the list containing this. If it was c, then it would have this. So do you know the difference between this statement and the statement below? Since, since this is an asterisk c, it has a, c becomes equal to a list containing this. So, so imagine if you replace the list containing this instead of c, instead of asterisk c, it would, wait, so let me show you. So, if you know the output, then this is how you can interpret this. And then, with an asterisk in the front. And then you know that this tuple can be unpacked to match this. So, actually that's why c is equal to this. Make sense? Is my explanation very good or is it too basic stuff? Because I can't believe none of you are raising any questions. Okay. So here, again, so put a bracket around this, one, comma, two, comma, this. Now you will think that there are four elements here. But remember that asterisk d can take an empty list because it's, it can be unpacked. So d becomes empty, a gets assigned to one, b gets assigned to two, and c gets assigned to this. Is this clear? Okay. Can you guys see this? You should have told me before. Okay. Now a, comma, b, comma, asterisk c, comma, b. So, a, again, you, again evaluate the ends first. So d becomes equal to this, a, comma, b becomes equal to one, comma, two. And asterisk c can take an empty list. So c becomes, so c is empty. Okay. Is this clear? This is only extended, I can eat Python 3, right? Yes. This doesn't work in Python 2. To see the proof. Oh, wait. I, I deleted that example since. Oh, wait. Here it is. Yeah. It doesn't work. How would you do this kind of thing? You would never do this. No. I mean, if you do this, then I mean, play for your life because the developer who will maintain your code after this would not like you. I found something similar in, like, some fashion in a language like sql. Yes. This is, yeah. So actually you can think of, I mean, if you're familiar with scheme, then actually you can think of, so, so in any functional language in a list, you have a car and you have a kidder. So car is the first element and the kidder actually gives you a list. So actually asterisk c does the same job. It does not do the same job, but we are talking analogies. So it's, so it's a list. So yeah, you are exactly right. This was an attempt to make it more functional. But I'm showing you how it can be used in evil ways. Okay. So again, a comma, yeah, this was when I thought I had too much time. So I print a, print b, print c, print d. So a comma, so again, two elements. A is equal to 1. B is equal to 2. No problem. C and asterisk d this. Now this is just one element, but d can be, oh, no, no. So here this is a tuple and this is, this is this. Now remember that this can be written as t comma h comma i comma s. So c is actually in functional terms, c becomes the car. So the first element, so c becomes, oh yeah, c becomes t here. And then, so actually if you have a list, t comma h comma i comma s in functional terms, car of this list would be t and kidder of this would be h i s. So this is the same concept. D is, is everyone clear with this example? Wow, my explanation must be wrong. Asterisk is equal to 1. Yeah, this, okay, this is simple because one is not a sequence and this expects a sequence. So it's clear, start assignment, target must be listed or tuple. Okay, now this one, why this one doesn't work? I don't know the exact reason, but I think it is because if there's no comma after this. So you see the difference between these two. The only difference is this comma. So if this is this, no comma actually Python does not think of unpacking. So actually it treats this as a mathematical expression. So to tell Python that we are still interested in packing and packing, you have to put a comma if it's a single value tuple. I'm sure if you have played around with tuples, then you know that you cannot write bracket one bracket because that gets evaluated as a mathematical expression which is equal to 1. If you want to make a tuple of, if you want to, yeah, I think instead of saying bracket one bracket. So if you want to make, if you write this, this is 1. But if you write this, yeah, this is a tuple containing 1, single element tuple. Is everybody clear with this? Okay, now this, yeah, wait, is there, oh yeah, I've already gone through this. Yeah, this one doesn't work because this, it expects an iterable or a string or a list and one is just an integer. So interobject is not iterable. Okay, here, simple, a gets evaluated to 1. Okay, here, oh yeah, because if you put a comma after this, again for the same reason as, for the same reason as this, this also results in an error because Python does not think that it is an, it is, oh sorry, Python does not think, wait, where was I? Yeah, Python does not think that this is actually a list. So if you put a 1 comma, oh yeah, and you put a comma here, then this actually works. Okay, now, again the same logic, one is not iterable, 20. What is the shortcut to jump from cell to cell? Does anyone remember? Okay, now what? Command M, A and B. Command M? No. Oh no. Dude, that was a no move. My face. Actually, I'm very happy that my room made messaging because the message just below that was even more embarrassing. Okay, I have to zone up. Okay, I don't like you. As this K comma B again, yeah, this is because this is, this can take zero elements. So this becomes a list with no element and B is 1. And this one again, you first evaluate the size, B can be allocated to 1 and A can, since A is a sequence, A is a list with no element. Here again, when Python evaluates this, it sees three arguments on the right-hand side and only two on the left-hand side. So too many values to unpack. Okay, here again, it sees three arguments on the right-hand side, two on the left-hand side. So, okay, this one gets, okay, no, no, that is not the reason here. You first evaluate the size. So it sees two elements, but this is a list. So C can actually be equal to a list of, C can actually be equal to 2 comma 3. But when it comes to A comma B and it only sees 1, it cannot assign two elements to 1. So it says that int object is not retrievable. Okay, here it sees two elements. So it's two elements, but the second element is a list. So first we evaluate all the non-list elements. So A comma B gets mapped to xy, A becomes x, B becomes y and C becomes 2 comma 3. Okay, again here, evaluate the two elements versus one element. No one is a list. So too many values to unpack. Three values here, it's only two. Okay, here. Okay, now this is where it gets interesting. This is Asterisk of tuples. So you first, Python will have no, so actually there are two arguments, but the first argument is a list. So you know that the number does not matter. You go to the sides first, solve the easy ones first. C is equal to 3. Then Asterisk A comma B gets mapped to 1 comma 2. A becomes 1. B becomes 2. Okay, Asterisk A comma B 1 comma 2. Yeah, because this is not a list or a start. Yeah, this is not a list or a tuple. If it was, if it had brackets, then it would have been different. Wait, did I put that example now? Okay. Again here. Okay, yeah. Oh, so the reason is that this didn't have a comma. Yeah, if you have a comma, then it works fine. Here, again you put a comma. So this is, this actually expects a list. And this, so A comma B gets in a list. It gets validated to X comma Y. And then A becomes equal to X, B becomes equal to Y. Here, again, yeah, if you put a comma, then this works. So notice the difference between 37 and 38. Yeah, oh, this does not work, but for a different reason. Yeah, then this is, oh, because in your tuple, you actually have only two values. While this will get expanded to four values. So it says too many values to unpack. Is everybody clear on this? Can everybody see? Or do you still have to guess? Can see that? Is this so bad? Oh man, you should not say things like this. Okay, so this, you put a comma. So everything is fine. Then you, so it expects a list. You come here. So T comma H comma I comma S. A becomes equal to T. B becomes equal to a sequence of HINS. Here, again, yeah, if you, if you don't have brackets around it, you put brackets around it. You, this, and since, so once you put brackets around it, asterisk of A comma asterisk B will, and C are two elements. Since the first, so we evaluate the sides first. C becomes equal to S. Now, A comma asterisk B will be equal to T comma H comma I. Again, evaluate sides first. A becomes equal to T. B becomes equal to H. Oh, well, this is a harmless image. Really? I have not got to the interesting part. Oh, yeah, let's get to the interesting part. But isn't this fun? Detention is the best. No. No, but I asked you a question. Why do we want to do this? Because it was just an exercise for, oh, we can do this in Python that actually has zero practical use. We shouldn't be doing it because Python is a language which teaches us not to do stupid things for a reason. Okay, fine. Let's go to the other stuff. Okay, so maybe I'll upload this on GitHub or something and I'll give you the link. But I'm not done. I'm not doing me. Okay, so let's get to it. Okay, so next time I won't go crazy with the examples. Let's move on to other stuff. Yeah, I mean, honestly, you will never be using this in any, hopefully, any production code. You could only use this in probably competitions which test how short your code can be. Sometimes it's useful. I happen to use the star notation when I don't really care about what's next. So I unpack the stuff that I want to and, you know, let the remaining stuff just pass along to the rest. So actually for star notation, I barely remember it used to be part of all the fight and then it would be moved and then it would be introduced. Because it doesn't work in Python 2. No, it works, but it doesn't. The extended sequence unpacking does not work. But the sequence unpacking works. This is Python 2. Yes, sir. We can test it out. I have never used the extension. I've never used it on the left-hand side. But on the right-hand side, it has its uses. Sometimes it is more useful. Decorators. Yeah, for decorators, it's... Yeah, it doesn't work. Decorators are one good example. Yeah, it doesn't work. Okay, so other Python basics. How many of you guys are familiar with this that Python has negative indices? Okay. I'm sure it's all of you, but some are too shy. So the minus one is actually the last element. So you can think of it like a circular loop or something. So A minus 1 becomes equal to 10. Then minus 3. The minus 3th index is minus 1, minus 2, minus 3. So this is 8. Okay, now list slices. Now A... So in Python, you can slice elements. Like you mentioned, the start index and the end index. It doesn't take into account... So actually the elements in our list are same as index. So 0th element is 0. First element is 1. If you guys are not... I'm sure everyone is aware, but in most languages, apart from R, I think, the indexes start from 0. Is this correct? R indexes start from 1, right? Anyone who is familiar with this? Starts from 1. Okay. Okay. Okay. Okay, I've never heard of this. Yeah, so 0, 1, 2, 2, 2, 8. But it does not take into account the last index. Okay, negative indices. Very same concept. Minus 1, minus 2, minus 3, minus 4. It includes the first index. Then this is the minus 3, minus 7. So 7, 8. It doesn't include the minus second index, which is minus 1, minus 2, which is 9. So this is why. Okay. Now if you have a step, step is the same as the range function. So here you... So this by default is 0. By default is the length ln a, which will be equal to 11 in this case. Because you see the number of elements in the list are actually 11. 0, 1 to 10 is 10. And then 0, you add one element. So it's 11. Starts from 0. 0, 2, 4, 6, 8, 10. It goes to 12. 12 is past the bounds of the list. So it just spends that. So here... No. Okay. At least the subject is nice. So you guys don't know what this is about. 3, 0, 3, 6, 9. Same concept. Oh, hi. Oh, sorry. Yeah. But just on the rock 2, apparently Pi Pi doesn't... It takes out the rock 2. So it uses the whole Tupel thing? It doesn't know the rock 2. Build Tupel and then unpacks? Pi Pi implementation of that... Okay. Do you know? I wonder why. Never mind. 2, 8, 2. Maybe it begs some guidance. Okay. I should get that. 8, 2, 8, 2. So 8 is the stopping index. 2, 4, 6. It comes to 8. It doesn't work. Oh, man. I should really execute this. Okay. So 0, 1, 2. Okay. Now this was interesting. I just put the negative step for fun. I expected it to go... First put 0 because I thought that it always starts from the first element. But then I found that if you have negative index, then actually it starts from the last element. I mean, intuitively, if you would replace the values, then I would do it like this. 0, lene, minus 1. But how they... So according to me, initially before executing this, I thought that the 0 element should be printed first. Running. Oh, yeah. Oh, because it starts from the last element, but the first element is greater than the last element. So on reading the C code, I found that whenever it's a negative step, then it always starts from the last... It tries to start from the last element of the index. But since we are forcing it to start from 0, so it cannot... So 0 is already beyond the... So it goes from right to left, but 0 is already beyond the... It doesn't include the first element, so it's an empty list. Let me see what happens if this is the one. Oh, well. Yeah. I don't think it will work. It will throw an error, because lene minus 1 or lene? Okay, let's try this. This should throw an error. Oh, well, it does not. Okay, so let me try this. lene minus 1. As far as I know, that's just like a shortcut for... Yeah, yeah, so exactly. Oh, okay. So earlier I thought that, I mean it always tries to follow the left to right sequence, but if it's a minus 1, then actually goes from 0 to left, but apparently that's not how it works. So let's go to my... Yeah, it's the same thing. Oh, so actually it does make a difference. So see, the 0 is missing. And if I try lene... Oh, so it's still... Oh, because this is... Yeah, minus 1. No. Yeah, that is what the initial one works. No, no, no. That might take out the most... Ah, okay. Is everybody clear? More experiments because I'm not clear. But... Good. But lene, there's no... But I thought this should be lene minus 1. But why does this leave out the... Oh, it does not. Minus 2. Yeah, it would probably work. Why is that? Because when you're iterating, you can give indexes that are out of bounds, and it won't error. It would just start from the... When you're doing slicing, when you're doing slicing operators, it does not throw an index error if you reference outside your index. Even with regular... Oh, is it? Yeah, just try... Actually try referencing something... So maybe 30 and then 50. Pretty sure. Yeah, so he's right. So what this does is it goes for... Oh, so it starts counting from 100, but it cannot find an element at 100. Then it goes to the... Oh, then it goes to A10, and then it finds an element. Okay, I'm clear. Finally, anybody of you guys still... Oh, so I was the last one. Okay, minus 2 to lene. So again, we know that it... So it just... This does... Because there's no negative step, so it still goes left to right. Minus 2 element is minus... So 9, 9 to 10. This is lene, the final argument. I guess that should work. Okay, this is minus 2, so minus 2 gets evaluated to 9, and then it just plans from 0 to that. Okay, list slice assignment. 2, 3 is equal to 0 to 0. So remember that when you slice, it doesn't take into account the second argument, it doesn't take into account 3. So this essentially means that A, 0, 1, 2... So 3 is the second element. So... And then 2 to 3, 3... It does not include 3 because 3 is the second assignment. So 2... So it replaces this value. Oh, why am I putting a finger there? You cannot see. It puts this to 0, 0. So when you print, you see, instead of 3, you have 0, 0. Okay, now 1, 1... It starts from... So here, you would think that the start index and the end index is the same, but the rule that I told you was that the end index is not counted. So you should think that nothing happens, but how it treats it as. So let's go to our list. Now this is A, 0, 1. This is the first element. It takes the first... It tries to take the first element, but the first element is greater than or equal to the second argument to the slicing notation. So it actually puts an element here. So you see 8, 9 are inserted before 2. And the list of the list remains the same. Everybody clear on this? Yes, no. My English sucks. 1, minus 1. Here, you start from the... The first element is 0. First element is 8. Minus 1 is 5. So it does not include minus 1. So 8 to 4. It puts this as empty. So it becomes 1, 5. Now you can name slices. So this is stuff that you can actually use in programs. So 0, 1, 2, 3, 4, 5. It slides from minus 3 to none. Then why do I put a none here? Let me try this. Oh, no. So it still works. So let me... Just let me do an experiment. So I don't... Wait, I put a none. So it does make a difference. So this is just the slice notation. This is just the step. And then A last 3. Minus 3 to none. So 0, 1, minus 1, minus 2, minus 3. And then it takes into account the... So it doesn't include this. It includes the first 3 elements. If I put... If I don't put a none here. Minus 3, none. Wait, why didn't it make a difference? Oh, okay. So here... So that code was not executed. That's what I was wondering. So it's minus 1, minus 2, minus 3. So it prints all elements from 3 to the end of the list. If you remove the none. So it treats this as the final argument. Minus 3 and then... So you get the first 3 arguments. Okay. Now this is... So if you want to iterate many a times, I want to have the index of the... Many a times when I write code, I want to act... So I often do... Instead of doing for i is equal to 0 to len of list, you can actually just do enumerate. So what this does is this i is the index value and x is the element. So 0 to... So 0 at 0th index, we have... So our list is 0th index. So hello, first index we have world and at the last index we have this. Now if I want to do... m... So we can do the same thing over dictionaries. But in dictionaries we can use... I mean there are other ways to do this as well, but this is the one I use as example. So here it's a key value pair. K is the key, v is the value and you print that out. It does not... Python 3 changed a bunch of rules. So in Python 3 you have to... They change it from items to items. I don't want to go into why this is the case, but yeah, because that would take another... Okay, now zipping. This is another very cool feature of Python. So what zipping does is... So here I print the description of zip. So zip actually takes the... all the tribals that are passed to it and then it takes the 0th index from each of the tribals, from each of the list, puts it in a tuple and then as the second element of the resulting list, it takes the first index of each of the tribals or list passed to it, puts it as a tuple. So 0th index, 1, A. First index, 2, first index of B is B. So you have 2, B. Second index of 3, A is 3. Of B is C, so you have 3, C. So and... But remember that... Now, so this is actually... What do you call it? Commute, no. In mathematical, in functional programming, there's a word for this when the relation applied to itself comes back to the same thing. Maybe inverse. Yeah, so, okay, this is not exactly inverse, but it's similar. So you see, you get back the two lists that you started from. So if you zip this and you pass this to zip. So again, the same rule of zip. It has three lists as arguments. It takes the 0th argument from each of the lists. 1, 2 and 3. So it creates a tuple out of the 0th arguments. Then it creates a tuple out of the first argument. Yeah. You can read the description probably clearer than what I explained. Okay, now... So if you have more than... If the number of arguments in the list is not the same, Python 2 just ignores it. So you have 1, A, 2, B, 3, C, but notice the 4... Since it doesn't have a corresponding element for B, it just ignores it. This is useful if you don't want to write code that checks for the number of... If you were to do it in a creative way, you would have to write code that actually checks whether both lists have similar elements or not and then write logic for that. So... Okay, now map. Map... Okay, so... So map just applies the function. So map can take... The first argument to map is the expression that you want to apply to the corresponding arguments. Now if instead of... So here we have 1, A, 3, B, Items. It applies SQR to all the elements in item. It takes each element in item. It applies SQR. First it does SQR 1. Square of 1 is 1. So it puts it in a list. Then 2 square, 4, 3 square, 9, 4 square, 16. And it outputs a list. Now suppose I had a square comma items. And this was... X. X plus X. What's wrong with me? Don't answer that. X comma Y. Oh, right, right, right. Of course. So here it has two arguments. It does the same stuff. It applies SQR. Since SQR accepts two arguments, that's why you were able to do this. So it takes in each element. So it takes in the first element from... Let me make it more clear. Now let me do it... 6. So is everybody clear on why this works? So we could increase it to 3 tribles or whatever. Then... Yeah, let me change it back. This is because the... Yeah, I should have declared a separate list for each cell. But okay. Now... This was again interesting. The API actually allows us to specify none. So if there is no... If there is no function to apply, then MAP actually does nothing. It just returns... If there is only one argument, then it takes each argument. It has nothing to do. So it just puts that argument itself in the list. Now if you have two... Then... It applies... It applies... So first it takes... So according to the nature of MAP, it takes the 0th argument from both the lists. It forms a tuple. But there is no function to apply it to. So it just returns the identity. So it applies the identity function. Yeah, identity function. And then it forms a tuple of 1, a, 2, b, 3, c. Now notice that this is exactly the same as MAP... As zip a, b. So zip a, b... I am not sure if the implementation is the same or not. But we can rigorously prove that the output would be... MAP none... MAP none a, b is equal to zip a, b. This is because none is actually treated as an identity function because there is nothing to apply to. Everybody clear on this? Yeah, I think it should throw an error. Okay, let's try. Actually it substitutes for none. Oh, is it? Ah, yes, he's right. And then let's see this. Oh, so now it gets a false because zip actually does not... zip... zip does not take into account... So zip would have 1, a, 2, b, 3, c, but it would remove d because it doesn't have the same length. Okay, so... Yeah, I'm... So you... So the way this is... because of the difference in implementation of how MAP puts a none if it doesn't find corresponding arguments, this... Yeah, this is false. Okay, now this is something that I wanted to investigate but I didn't get time. So can someone explain to me how this gets evaluated to this? No, this is a serious question. I don't know the answer. But this is how it works. We can see your intentions. Oh, so you can't see the intention. Okay, you can see them. So I was... So I was just searching for applications of zip that... So that can... So, yeah, so I just found this interesting example. And I found this when he was giving his talk. So I didn't have enough time to investigate and I don't understand how this works. So if any of you guys know how this works, please do help us or help me. If not, that's pretty much the end of my talk. Any questions? Or do you want to go to the unpacking examples? Okay, fine. Don't like it. Yeah, okay... I think it doesn't make sense. Unless I'm the lecturer and I'm giving points, I don't like to leave as exercise because you guys would never look at it. All the love that I spent in... Okay, so that's then. Any questions? Any feedback politely? Oh, yeah, so I do have to advertise this. So I just started this startup and it's in the area of big data and healthcare. Okay, so the backend is not based in Python. I mean it was earlier based in Python and I moved to Node.js. That's for another day. So earlier I was using Django, but yeah, we are looking for everyone. So... I mean, we have a lot of people, but we are looking for more. Okay, so thank you for coming to the meetup. Can you open the tags around the display? Oh my God, this is so cute. Actually, that was intentional. Oh, that was intentional. Oh, come on. Yeah, so if anybody wants to help with our website, this is from GitHub, their instruction how to help. For those of you who are new and if you want to, like, we have a learning page under... I didn't know you would have all this stuff. So either you're starting from scratch or if you know another language but you want to quickly romp up Python so we put some links for developers and I would point the second link for developers that code like a Pythagorean. So a lot of... So there are good examples of Pythagorean that exist. I'm not shutting you down. Yes. But... Maybe I should evaluate what the... Referred to the previous talk by Martin, he actually said how to evaluate whether a code conforms to PPA or not. I should look at my score. But that is not how I usually code. That was just for the start. I'm a good coder. Thanks for coming, guys. Sorry the meetup started late. Yeah, two. It's pretty nice and relaxed conference. We had three nice keynote speakers there. Oh yeah, the keynote speakers are awesome. The first two are associated with Django and the third one I'm not sure. Oh, she... Oh, she maintains Twisted. I don't know what is OpenHatch. In some necks of her engineer What? Profession. Which one, which one, which one? The second son. He wants to get paid by the hour. Son, man. Hey, who wrote the description? Did they send it themselves? She feels proud about it. I mean, I assume since she sent them the description. No, but she doesn't look sleepy from there. No, but she doesn't look sleepy from there. So she doesn't need it. Yeah, but... I don't know, actually, ask her. Yeah, so actually for this kind of meetups we don't need to... we don't need to prepare slides or anything and we also don't need to... Again, a low blow. I didn't prepare slides. It's good. Oh, okay. Yeah, even if you have like five to ten minutes. So last time Martin started something. Yeah. Tips and tricks. Whatever modules you have discovered, which is useful. But history... But his tips you should use in your code. My tips, you should not use in your code. I mean, not all of them. Yeah, so it's nice to see gaming people. So we would like to see... We haven't had a gaming talk when playing in this season. So that's one thing I realized when everybody introduced themselves. I have no clue about most of the things that people work on and being nice to hear about that. I mean, I don't know much about big data or gaming or... Yeah. Rest of the stuff. Research. So, yeah. It would be good to hear some... One of the things that happened last meet up was I heard about PyTest and although I've been using Python for a very long time. I'd never bothered to check it out and it's... So, you know, it's good to learn about something without actively looking out for it. So, yeah. You shouldn't mention research because the research publications are actually noted, so I'd be more than happy to bore you with the whole paper. I'll show you guys my program. But sir, I don't... Sure, it's the next... Sure, sure.