1 00:00:00,180 --> 00:00:06,960 So we get the value python hacking now, this could loop through each character in the string python 2 00:00:06,960 --> 00:00:12,690 hacking and concatenate it to the end of the string, which is stored in the building as MediaVest. 3 00:00:12,870 --> 00:00:16,350 So at the end of the building is holds the complete string. 4 00:00:16,740 --> 00:00:23,310 Although this particular string concatenation seems like a straightforward technique, it's very inefficient 5 00:00:23,310 --> 00:00:29,340 in Python because it's much faster to start with the blacklist and then using append list method. 6 00:00:29,640 --> 00:00:35,430 So when you're done building the list of the particular string, you can convert that list with a single 7 00:00:35,430 --> 00:00:38,170 string variable by using a joint method. 8 00:00:38,430 --> 00:00:43,860 OK, so instead of this particular code that we have done, we will write down similar code, which 9 00:00:43,860 --> 00:00:47,480 will do the same thing as this particular code has done. 10 00:00:47,730 --> 00:00:53,390 So over here we will create the building as is equal to open closed bracket. 11 00:00:53,800 --> 00:01:03,750 Then we are creating four seven in C Biton hacking open the for loop then here we are seeing building 12 00:01:03,750 --> 00:01:08,310 is set up in the value of C one to it. 13 00:01:08,970 --> 00:01:09,420 Then 14 00:01:12,750 --> 00:01:23,340 let's go here and then we see building as is equal to single code or join the value of building us and 15 00:01:23,340 --> 00:01:25,880 then we give operand command building. 16 00:01:26,820 --> 00:01:28,590 It also gives us the same output. 17 00:01:28,890 --> 00:01:35,700 So using this approach to build up string instead of modifying a string will result in a much faster 18 00:01:35,700 --> 00:01:36,360 programs. 19 00:01:36,540 --> 00:01:41,550 And you can see differences of time by two approaches using the time, the time method. 20 00:01:41,760 --> 00:01:47,490 Now, just to test this, we will create a new file in the ED window and we will enter certain coding. 21 00:01:48,810 --> 00:01:55,520 So let us go for a new file and the first thing we would do is we would import your time. 22 00:01:55,960 --> 00:01:58,220 Then we would see start time. 23 00:01:59,880 --> 00:02:02,660 One is equal to save time or time. 24 00:02:03,300 --> 00:02:10,820 Then we run for the one in the range and we will give here in say ten thousand. 25 00:02:12,200 --> 00:02:13,830 OK, a bigger number for it. 26 00:02:14,310 --> 00:02:24,720 Then we have your C malingers is equal to the first method that we had used for Iven in the range of 27 00:02:25,350 --> 00:02:26,230 ten thousand. 28 00:02:26,430 --> 00:02:36,770 We are seeing malingers plus is equal to say concatenate X and after this you run Alperin. 29 00:02:36,780 --> 00:02:44,580 Come on the c c string concatenation colon comma. 30 00:02:44,680 --> 00:02:51,440 Here you put in the value of time or time minus the start time one that you had. 31 00:02:51,570 --> 00:02:53,760 So the exact time would be put in there. 32 00:02:54,060 --> 00:03:00,160 Now once we have done this again, we would create this start time to is equal to again. 33 00:03:00,160 --> 00:03:07,490 So time or time and again here we would take the two in the range, same range. 34 00:03:07,500 --> 00:03:08,160 We will take four. 35 00:03:08,160 --> 00:03:11,730 That will get the exact difference we have. 36 00:03:11,730 --> 00:03:19,440 Your building is which is equal to a list now and again here we are saying even in the range of ten 37 00:03:19,440 --> 00:03:20,280 thousand again. 38 00:03:21,240 --> 00:03:25,560 And once we open up this year, we say building is not. 39 00:03:25,560 --> 00:03:35,980 We use the append matter and we say append the value of X, after which we say building S is equal to 40 00:03:36,750 --> 00:03:40,070 join the value of building us. 41 00:03:40,890 --> 00:03:55,050 And finally we give up trying to come on c c list, appending colon and reprint here time or time minus 42 00:03:56,850 --> 00:03:59,000 start time to in this case. 43 00:03:59,760 --> 00:04:06,210 Now let us save this just to rebuild or save it in our E drive. 44 00:04:07,520 --> 00:04:11,870 An advanced level course and let us give your name, see? 45 00:04:12,930 --> 00:04:16,630 Best string dog fever. 46 00:04:17,250 --> 00:04:20,130 And now if we try to run this module. 47 00:04:22,240 --> 00:04:28,950 It will take a certain time because we have given a range of ten thousand there, so we will get how 48 00:04:28,960 --> 00:04:34,730 the string concatenation works and we will also get to see how the string list works there. 49 00:04:35,140 --> 00:04:43,330 So let us just wait and see the output, what it comes for, string concatenation as well for the string 50 00:04:43,330 --> 00:04:48,280 or the list of spending that we have used their serial string. 51 00:04:48,280 --> 00:04:54,580 One calculation, look how much time and again, let us now check for the list of spending to work and 52 00:04:54,580 --> 00:04:55,980 get the similar output. 53 00:04:56,320 --> 00:04:59,230 So list up only to how much time it is. 54 00:04:59,230 --> 00:05:01,590 A lot more differences if you find out this. 55 00:05:01,900 --> 00:05:04,470 So now we have set here the variable. 56 00:05:04,480 --> 00:05:10,840 If you look at this, the string program, which is your start time one over here, the first variable 57 00:05:11,440 --> 00:05:18,720 that is sitting as the current time and the cold runs here for ten thousand times and it upends the 58 00:05:18,940 --> 00:05:25,240 ten thousand characters to a string using a concatenation and then prints the time it took to finish 59 00:05:25,240 --> 00:05:26,310 the concatenation. 60 00:05:26,680 --> 00:05:33,880 Then the program resets your or sets another time in start time to be able to the current time again 61 00:05:33,880 --> 00:05:41,110 runs the code and used this time the list of spending method to build a string of the same length and 62 00:05:41,110 --> 00:05:43,330 then put in the total time to finish. 63 00:05:43,650 --> 00:05:46,660 Now every computer made for what time you're getting. 64 00:05:46,900 --> 00:05:53,710 So in this case, if you just look at the output, it has taken 50 for about seconds for the string 65 00:05:53,710 --> 00:05:54,730 concatenation. 66 00:05:55,030 --> 00:06:00,810 But using the list up and process, it took the same task in just 18 seconds. 67 00:06:01,090 --> 00:06:07,100 So if the program builds a lot of strings, using list can make a program much faster. 68 00:06:07,480 --> 00:06:13,420 So now we will use the list up and join forces to build strings for the remaining programs in this particular 69 00:06:13,720 --> 00:06:14,330 session. 70 00:06:15,070 --> 00:06:20,590 So we'll continue Murong discussion of all the programs that we have already done in the next session. 71 00:06:20,630 --> 00:06:21,880 That's it from this session. 72 00:06:21,910 --> 00:06:22,900 Thank you very much.