----BEGIN CLASS---- [13:27] #startclass [13:28] kushal: ok [13:28] Roll Call [13:28] Jason Braganza [13:28] Ashwani Kumar Gupta [13:28] Anu kumari Gupta [13:28] Bhavin Gandhi [13:28] Abhishek Singh [13:28] Kshitij [13:28] ashwanig thanks for suggestion [13:28] Priyanka Sharma [13:28] Soumam Banerjee [13:29] Mahendra Yadav [13:29] Gaurav Sitlani [13:29] Saptak Sengupta [13:29] Robin Schubert [13:30] Yurii Pylypchuk [13:30] Okay, questions on strings chapter? [13:31] Any questions? [13:31] for once I understood [13:31] that’s [13:32] Roll call: Onyinye Madubuko [13:32] ! [13:32] that’ll obviously be tested once I have to solve a problem though :) [13:32] Which method to call to break a string in different parts? [13:32] kushal: split() [13:32] :) [13:32] kushal split() [13:32] next [13:32] split() [13:33] split() [13:33] Where can I find more information about %s and %d in -- print("%s 's total marks %d" % (x, total)) [13:33] yurii, wait, providing [13:34] yurii, though better to use .format and f-strings [13:34] I will have to update the book for that. [13:35] Roll: Akash pathak [13:35] ! [13:35] Roll: Sandesh Patel [13:35] Roll: Krishnanand Rai [13:36] yurii, https://docs.python.org/3/library/stdtypes.html#old-string-formatting [13:36] next [13:37] ashwanig which part of my code is difficult ? and i lost connection after roll call please pass me logs. [13:37] kvy, discuss it after the session please. [13:37] kushal ok sorry [13:37] Did my first pull today, small GUI for kshitij's dice game :) [13:38] skarpy, If you can not see, there is a session going on. [13:38] skarpy, otherwise, congratulations. [13:38] Oops. Sorry. [13:38] skarpy, Was that the question? [13:38] Sorry, but now I am totally confused. [13:39] skarpy, Just finish the message as or something so that we know :) [13:40] Anyone else, any questions? [13:40] Today's problem, to be solved during the session [13:40] lines = """MemTotal: 7858500 kB [13:40] MemFree: 647000 kB [13:40] MemAvailable: 2487576 kB [13:40] Buffers: 244416 kB [13:40] """ [13:41] Tell me the free memory, total memory, and available memory in MB [13:41] :) [13:42] kushal: we have to read these information from lines? [13:42] https://paste.fedoraproject.org/paste/MIJBk0P3N7wAVkJ7Dnp~fA [13:42] there is a variable already [13:43] copy paste [13:58] session is going or not? [13:58] poojaencoded: https://paste.fedoraproject.org/paste/MIJBk0P3N7wAVkJ7Dnp~fA task is to print kB in MB [13:59] My connection is lost someone please pass me the logs till now. [14:00] https://notebooks.azure.com/n/9vUasNwt1yg/notebooks/summertraining.ipynb [14:01] kushal: done. [14:03] asraisingh, now do free -m in terminal [14:04] kushal, https://paste.fedoraproject.org/paste/Ou3v59Msl5bkMwZoRmzLmg [14:04] does it say 7674.31640625 ? [14:04] kushal: done [14:04] people try out your own answers first, and then think, and then only show us [14:04] sorry, i have to use int for it. [14:05] kushal: https://notebooks.azure.com/kshitiz/libraries/dgplug/html/summertraining.ipynb [14:05] I want to store word in dictionary [14:05] But it's throwing error [14:05] Index out of range [14:07] ikshitij, yes, the last line is an empty line :) [14:07] Oo [14:07] kushal, https://paste.fedoraproject.org/paste/f9UiCO6OxKlj5jQrzie2Pw [14:08] ashwanig, yes, checked [14:08] ashwanig, those print function calls look bad [14:08] kushal: error corrected, https://notebooks.azure.com/n/9vUasNwt1yg/notebooks/summertraining.ipynb [14:08] You can make them better [14:08] kushal, ok should I use .format() ? [14:09] ashwanig, yes, better [14:09] asraisingh, not correct answer, I can see some random numbers [14:10] asraisingh, You will have to give an output which makes sense. [14:10] Here I don't know which line is what. [14:11] brb in 15 minutes [14:11] Roll Call:Deepika Upadhyay [14:11] done. https://paste.fedoraproject.org/paste/8t~V9y918KBUL2iJEM2OUw [14:12] https://notebooks.azure.com/n/hyeu6kOvr2M/notebooks/summertraining.ipynb [14:14] https://notebooks.azure.com/kshitiz/libraries/dgplug/html/summertraining.ipynb [14:14] Done [14:15] knrai1, the results will be integers not float [14:16] ikshitij, We have to convert the memory values into MBs [14:21] https://notebooks.azure.com/n/9vUasNwt1yg/notebooks/summertraining.ipynb how to convert this data to an array , i am getting error [14:22] kushal: Working https://notebooks.azure.com/kshitiz/libraries/dgplug/html/summertraining.ipynb [14:23] https://notebooks.azure.com/bhavin192/libraries/dgplug/html/summertraining.ipynb [14:23] ashwanig: okay [14:23] championshuttler, we don' [14:23] championshuttler, we don't have normal array in Python [14:24] kushal: ok i am trying to do but getting error, is there anyway? [14:24] for once, I think I got something running [14:24] please check - https://notebooks.azure.com/jasonbraganza/libraries/dgplug/html/summertraining.ipynb [14:25] https://notebooks.azure.com/n/nlnVjJirBnQ/notebooks/summertraining.ipynb [14:26] kushal: https://notebooks.azure.com/kshitiz/libraries/dgplug/html/summertraining.ipynb Corrected again [14:27] jasonbraganza, total_memory = (split_lines[0]) you can just write total_memory = split_lines[0] [14:27] Now for a line like [14:27] "MemTotal: 7858500 kB" [14:27] i don’t know why i keep doing that. sorry. will go fix [14:28] what is the best way to split? [14:28] People please discuss [14:28] i couldn’t quite figure out so I mashed last time’s expression :) [14:29] kushal, for that we can use line.split(':') [14:30] split("\n") [14:30] ikshitij, Won't that return the original line itself? [14:30] ikshitij, where do you find the "\n" [14:30] ashwanig, :D [14:31] I think the same -- line.split(':') [14:31] ashwanig - yes! i forogot! [14:31] s /forogot /forgot [14:31] That was an example [14:31] :) [14:33] ! [14:33] that would have been my solution https://paste.fedoraproject.org/paste/znTvZfC09w4F-KaCvmLTVw [14:34] I did lines.split() and then checked the words [14:35] sorry asking out of turn, Is there any function to remove those spaces from the middle without splitting? [14:35] kushal: I stored lines in word by line.split(":") and then replaced all spaces by using replace(" ","") [14:36] Then stored word and size in Dictionary as key and value respectively [14:36] Is this okay [14:39] ikshitij, there can be different ways [14:39] ikshitij, nice method :) [14:40] schubisu, alao print what is what [14:40] kushal: okay [14:41] Using indexes directly makes reading the code a little hard, like word[0]; what do you think guys? [14:41] bhavin192, yes, I also have this doubt [14:41] https://notebooks.azure.com/n/MBHpc8gojiM/notebooks/summertraining.ipynb [14:43] bhavin192: but what, when we have two values only in list, running loop unnecessarily is also not a good idea [14:43] I am in doubt for this [14:44] ikshitij, you can always add comments or new variables may be like some_index = number [14:44] I'm not sure though [14:44] bhavin192, if you know the data, you can do that [14:44] with comments [14:45] Just use index numbers but with comments [14:47] kushal, next problem? [14:47] kushal, what do you think about this the `buffer_index` https://notebooks.azure.com/bhavin192/libraries/dgplug/html/summertraining.ipynb [14:47] kushal: sorry, what do you mean with print what is what? Add comments? [14:47] Is anyone have any other questions? [14:48] schubisu, like what output is the free memory [14:48] "Free memory" [14:48] Is mine correct? [14:48] anuGupta, you are missing spaces around operators [14:49] anuGupta, and also the code looks scary [14:49] Split is not splitting ":" [14:49] anuGupta, example? [14:49] listing=lines.split() <- anuGupta [14:49] kushal: it should be in there. Sorry for not posting in a notebook so you can't see on one glance. [14:50] Example "me mTotal:" is one of the element of the list [14:50] schubisu, Okay [14:50] bhavin192, if you are extracting the substring before the for loop, then what is the need for this `if word.find(":") != -1:` ? [14:50] Every [14:50] Everyone, try not to use a loop [14:50] as this is a fixed data [14:51] ashwanig, I'm removing the buffers part only [14:51] Kushal, What exactly is scary? I hear this in my every code. [14:51] ashwanig, then checking if the word has ":" [14:52] anuGupta, have you read my message? [14:52] bhavin192, I am using .split() only [14:52] anuGupta, you are missing spaces around operators listing=lines.split() <- anuGupta [14:53] anuGupta: you should give space after operator [14:53] bhavin192, Every combination has that, then why checking? [14:53] x == 7 not x==7 [14:53] anuGupta: [14:53] Ooh [14:53] ashwanig, I'm splitting with .split(), so I have kB as well [14:54] ashwanig, to avoid that [14:54] Thank you [14:54] bhavin192, Oh got it [14:55] https://notebooks.azure.com/n/nlnVjJirBnQ/notebooks/summertraining.ipynb [14:56] ashwanig: how to pass multiple argument in .replace() [14:56] ikshitij, what will it do? [14:57] https://notebooks.azure.com/n/TB0RRLB9wtM/notebooks/stringProblem.ipynb [14:57] laptop crashed, will take 2 minutes [14:57] Check comment with line 1 and line 2 written [14:57] anuGupta, I will answer you [14:57] anuGupta, for example [14:57] if(listing[i].isdigit()==True): [14:58] if statement does not need () [14:58] so that statement becomes if listing[i].isdigit()==True : [14:58] now [14:58] anuGupta, if you remember https://pymbook.readthedocs.io/en/latest/ifelse.html#truth-value-testing [14:58] that line can now become [14:58] if listing[i].isdigit(): [14:59] anuGupta, Isn't that cleaner? [14:59] Yes kushal [14:59] Understood [14:59] listing[i]=str(round(int(listing[i])/1024)) + " " [14:59] I can only imagine what it is doing [14:59] anuGupta, remove the loop [14:59] don't use any loop [14:59] and then try to rewrite that oce [14:59] code [14:59] Ook correcting [15:00] S/ook/ok [15:00] anuGupta, your code is correct, but looks like C than python [15:00] kushal I think this code is converting list item into integer then again to string after division [15:00] Am I right ? [15:00] Yes ikshitij [15:01] Tonight problem [15:01] why string again ? We can store integer into list also @anuGupta [15:01] Take the whole file as a string in triple quotes from https://dgplug.org/irclogs/2017/Logs-2017-06-18-13-41.txt [15:02] and then write a code, which will tell me, 1. How many total different nicks were present in that log [15:02] When I am joining back to string , it requires all the elements to be string [15:02] who spoke how many lines [15:02] and how many words [15:02] 3 things [15:02] roll call [15:02] ikshitij we have something more strong then link-list. [15:02] Anu kumari Gupta [15:02] Jason Braganza [15:02] Robin Schubert [15:02] devesh verma [15:02] kumar vipin yadav [15:02] Kshitij [15:02] Abhishek Singh [15:03] Bhavin Gandhi [15:03] Ashwani Kumar Gupta [15:03] Solve this problem, who ever is doing this first, mail the link to the notebook to the mailing list [15:03] Priyanka Sharma ----END CLASS----