 Let us get started. The question asked is given a dictionary of names of students and their marks. Obviously, the key will be the name, value will be the mark. Identify how many duplicate marks are there and what are these? I thought it is a fairly straight forward question. So, if you have a dictionary, I would not type long names, please. If a dictionary like this, how do I look at all the names alone? Will give me a list. Please note that the order is rarely the same as we entered. That is one of the hallmarks of a dictionary. Dictionary is unordered. You cannot rely on any order. This will give us the marks. How do you find out how many marks are duplicates? That is the question. Given a dictionary of names of students and their marks, identify how many duplicate marks are there and what are these? It is not that simple to do, but in Python, you always think in terms of, let me add one, good high level data structure. Let me put in some duplicates now. So, 67 is duplicated, 78 is duplicated, 67 is duplicated three times 78 twice. Now, look at what are the question ask us to do? How many duplicate marks are there? That is the first. So, how do I remove duplicates? Because once I remove duplicates and I subtract, I know how many items are there here. I know there are six items. If I am able to remove the duplicates in the marks dot values, then I can immediately identify how many duplicates are there. Anybody, how to remove duplicates? In Python, you think in high level. There is a high level data structure called a set, which is sets do not have duplicates. After starting, you have to compare lattice, ticking, retail, think wholesale. Sets are unordered, sets do not have duplicates. So, length of this minus length of that gives you the answer. So, there are three duplicates. Now, which are these? That is a tricky problem. Why? Now, you know 67 and 78 are the duplicates, but how do we know? The only way is to look through each of these, count how many times it occurs in the original. So, that is the only way. So, let us go back and write a code. I will assume the dictionary is called marks. I will not type anything there. Let me type something there, otherwise there is a problem. I think I managed to reproduce that. So, these are the two duplicates. So, this is the code. We use a set called unique marks and then we step through the unique marks. For each of them, we find the number of times it occurs in the marks dot values. If it is whichever number it is, the number of occurrence is more than 1, we know it is a duplicate. Yes, Bhopal? In the duplicate marks question, we can pick up a mark and subtract it from all the marks. Wherever we obtain the answer as 0, they both are all the duplicates. Not only will we come to know how many duplicates are there, but we will also come to know their positions also in that case. True. True. The problem with that approach is only that you have to scan the list. If a list is 100 elements long, you have to scan the list 100 times. Are you with me? If the list is 100 elements long, you are going to read the entire list 100 times. You are going to read the entire list 100 times. Yes sir, I am with you. Yes. So, that is the first problem. The second problem is a little more interesting. Let me move to the, where is mine? If this is the list, your method will take the first 67, subtract from others. Am I right? Take the first 67, subtract 67 from 87, 7. So, you do not have to subtract the first 67, correct? Yes, of course. And keep on going. Now, you will get two 0s, which are the duplicates. Now, the next 87 when you take, are you going to go back to the previous ones or not? Anyway, you have to go to the previous one, but the current one you should not subtract, correct? You remember that you are in position 1? The position value will not subtract. That is what. So, you have to remember where you are, not subtract. The current position will not subtract. Yeah, but you have to scan the entire list. In other words, the list will be scanned 6 times in this case. That is a little slow. Yes, of course. The same method can be done faster in python, not necessarily one at a time. In python, you think wholesale like I keep saying. Instead of subtracting, you can merely count. What if the position was also required? What if the position also required is? The original position where the duplicates occurred was also required. Very good. But that is not a very clear cut statement, correct? That is not very unambiguously defined. So, you are saying the first 6 is… Now, first of all, we have to decide that the first 6 is original, rest are duplicate. That is an arbitrary decision. You are assuming you have made the arbitrary decision? Not a problem. Let me tell you the pythonic way of doing that. Let me just think it through for a minute. Let me think a little, but I am not happy about scanning the list multiple times. I am definitely not happy about scanning the list multiple times. There you go. That is faster and you know the positions. Yes, Bhopal. Any questions? No more questions from me and thank you from MNIT, Bhopal. Welcome. So, that was very interesting line of thought from Bhopal, which gave us a slightly different approach. Now, this finds which are the unique marks and which are the marks that are duplicates. Now, another way is like I wrote in the code just now, is instead to count each mark, but that requires to use a construct called a list comprehension. Not a problem. Without a list comprehension, the same thing can be done. So, we will build a list of count of each values. For this, we will say, we will build a mark count list. Mark count is a list. So, what we will do is, this will step through the marks. This is the equivalent code, which I wrote in one line here. The same code you have this much of work to do, but whether we do four lines of code or one line of code is not the issue. At the end of this code, what do we have? Mark count will contain. What will it contain? Let us print mark count and see. So, this is what we have. So, from this, we can determine which are the duplicates, which are also. So, how to determine the duplicates? Whenever the count is greater than one, we know it is a duplicate. We have to go through this list. Mark count of i greater than one. That means, that is a duplicate. So, this prints the duplicates. So, this is the amount of work you need to do if you are going to go through the non-set route. So, the set route on balance is much faster if you are trying to determine which are the duplicate marks. But this method can work better if you want to do something slightly different, namely find the way which positions it occurs. Then this method works better. We will move on to the next problem. Rajalakshmi, you had asked for 23. That is 23 in my list. This is a classical problem often asked many a times. It is called coalescing a list actually. Now, from this you have to produce the list like this. From that string you have to produce this list and then be able to answer questions about in the range 6 comma 15, which are the numbers missing in this particular list. You understand the problem statement? From S, you have to go to D. That is what is called coalescing a list. Let us sorry not that is not called coalescing a list. Coalescing a list is a different problem. But how do you go from here to there? We cannot assume in general that in S the first item alone is multiple the rest are single. Rather we need to scan each one by one and then figure out how to expand that. So, let us see. We have this. Now, how do you break it up into pieces? Split is the answer. We use need to split on a comma. That gives me a list of items of this type. Now, some of the items are individual numbers. Some of the items are ranges in the everyday sense of the term not python sense of the term. So, I have to find out which is which and then deal with them accordingly. So, this gets us what we want. Let us go ahead and use this to write the code. So, for S dot split will give me a range. I want to split on a comma. It is a good programming practice to do. Start with an empty list. I do not know what to do. For the moment, I will just bunk the thinking and then say. So, let us see how this works. It works, but I did not give any print statement. So, I do not know how it works. So, it works half way. Now, I have to find a way of what should I do if there is a minus. Anybody wants to attempt an answer? That we know. It has a minus. Split using what? Split using what? Very good. That is the correct answer. One small technical problem remains. Split will return. Two technical problems remain actually. Split returns strings. So, you have to convert that and range does not include the last element. So, you have to remember to put plus 1. That is all. Let us see. We got it. This part is over. This is the best way to go about doing it. Set up a large scale structure of the program. Do whatever is possible for the other. Make a dummy thing and keep checking. This part at least is working. The most important thing is to have a running program all the time. It may not do everything you want to do, but it should be running. What is the next step? Now, we are going to be given another range and we have to find out which are not in that. You cannot subtract two lists. So, how do I find out given two lists which are the members of one list not in the other? One way is to step through this list finding out whether it is not there. That is possible. You can do that. Find the numbers missing in this list for a given range. So, let us use range 6 comma 18. Now, what I can do? This is one way. So, this is one way doing that. The other alternative is to think whole set. That is to write something like works as expected. So, this is a more pythonic way of doing it because you can subtract two sets and find set A minus set B is set of all elements of B which are not in A. So, we convert it back to a list because we do not want to print a set. Now, I would like you to do this problem. Then we will discuss the solution and stop for the day. Close to the middle of the screen. There is already a similar problem in the exercises which you should have done. So, the input which will be given to you is 5 and you should print. The input will be given to you will be an odd number always. You can be certain about that. Your objective is for a given number 5. This is the output. This should be printed as close to the center of the screen as possible. Take 10 minutes and try and finish it. At 455, we will start the discussions and then continue. Anybody has completed or gone half way would like to share how they approached it? Anybody? I would not write the full code. Instead, I will tell you the way to approach it. Once again, you have to think in large chunks rather than think in terms of the individual stars. Like I said, as long as possible, avoid printing till the very end. Assuming you are given number is like I said 5, we have to produce a star of this type. So, write a function which will return the top from it, which is the top half. Then once you have the top half, what do you have? If you have written it correctly, the top half should return this. So, it will return a string containing this, one long string containing this, which means essentially return this slash n plus that slash n and so on. Now, once you have got it, you have got the rest of it already. You can either get it as a list of one long string with slash n or a slightly better method is for it to return 3 strings, a list of 3 strings without any slash n, which we can add later. If you get a list of 3 strings, then the second half is pretty easy to produce. Simply take these two. I will do a cut and paste that tells you what has to be done programmatically. If I take these two, the first two elements of the everything except the last element I can take, then reverse the order, I got it. Tink in big chunks. Do not write each line, each and every line of code. So, get top from it. So, bottom equal to, we will get top from it, we will return a list of strings. Bottom equal to, we have to take the last but one line of top and then reverse it. Now, we simply have to write, get top from it. Once again, you want to return a list of strings. So, if it is n, you know there are n strings to be returned. So, like I said, have a working program always, then fine tune. We got the basic thing right. We just have to space it properly now. Now, this is a very important method to keep doing things. Please ensure that you have the large scale structure in place and it does most of what you want. Now, many people what they will do is they would have written some 4 and a half lines and stop. Now, the program would not run. It would not do anything. So, if somebody wants to know, are you done? You cannot give an answer. Now, I can say my program I need to format the individual lines, otherwise I am done. That is all. So, the moment I say that, I know instead of printing line, if I say write a function called format which takes the given line and put spaces before and after as required and prints I am done. Now, we just have to write one more function called format. Now, in format what should I do? It is supposed to be approximately centered on the screen and there must be one space between each character. So, first I have to find I will use 50 because I got it in a very big way. Let me repeat. If you think in high level chunks, python is particularly conducive for that, it will do it very correctly. Can we say for I in range print str of this? St. Joseph's Kerala had asked the question, can we write this code? Well, you can write this if the problem I have asked was different. You know what will happen? We will run it. This is what it will print. I will change it to 50 to suit my screen. This is what that will print, but what we wanted was something else. Problem 1, problem 2, the way you have written for 5, it gives an output of 4. The way I have written will work if is more useful because I can, if you have seen the problem sets, you would have seen a problem like this. Print a permit of this form, correct? What problem number is that? It is problem 14. Problem 14 and 15, the way I am writing, if I write problem 14, it should take me another half a second to write problem 15. I just have to change format. Now, let us produce this sort of a permit. So, what am I supposed to do in format? Each line contains 2 and plus 1 stars. Please note the rest of my program does not change. I only format the individual lines differently. Now, I am producing a very different permit for just the, alright. We will stop here for the day.