[Tutor] doubt in a program
Hi, I am a new beginner in programming. I saw a code (given below) to reverse string. newstring = '' oldstring = 'Newton' for char in oldstring: newstring = char + newstring print(newstring) Could someone explain how it is traversing to get the string reversed? As the new character is adding the char in the new string but how is it getting reversed without any line giving the char number to be traversed in reverse order. Thanks, Vinod ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt in a program
On 29/01/18 06:42, vinod bhaskaran wrote: > newstring = '' > oldstring = 'Newton' > for char in oldstring: >newstring = char + newstring > print(newstring) > > Could someone explain how it is traversing to get the string reversed? print statements are your friend. Add print statements everywhere that a variable changes value: newstring = '' oldstring = 'Newton' for char in oldstring: print ("char=",char) newstring = char + newstring print(newstring=",newstring) print(newstring) That will let you see how the newstring gets built up inside the loop. You could do the same thing using a paper and pen, just walk through the code in your mind and write down the values each time, like so: charnewstring N N e e = N -> eN w w + eN -> weN etc... > As the new character is adding the char in the new string but how is it > getting reversed without any line giving the char number to be traversed in > reverse order. As you will see if you do either of the suggested exercises the addition always puts the latest char at the front of the newstring. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt in a program
Vinod, First time it loops, newstring = ‘’ oldstring = ‘Newton’ char = ‘N’ char + newstring = ‘N’ + ‘’ = ‘N’ Second time it loops, newstring = ‘N’ oldstring = ‘Newton’ char = ‘e’ char + newstring = ‘e’ +’N’ = ‘eN’ Third time it loops, newstring = ‘eN’ oldstring = ‘Newton’ char = ‘w’ char + newstring = ‘w’ +’eN’ = ‘weN’ Fourth time it loops, newstring = ‘weN’ oldstring = ‘Newton’ char = ‘t’ char + newstring = ‘t’ +’weN’ = ‘tweN’ Fifth time it loops, newstring = ‘tweN’ oldstring = ‘Newton’ char = ‘o’ char + newstring = ‘o’ +’tweN’ = ‘otweN’ Sixth/Final time it loops: newstring = ‘otweN’ oldstring = ‘Newton’ char = ‘n’ char + newstring = ‘n’ +’otweN’ = ‘notweN’ newstring after loop finishes will be ‘notweN’ which is the reverse of ‘Newton’ Let me know if that explanation helps you understand it better. There are built in functions to reverse a string that are more efficient than this approach that you should be using to reverse a string. -- Thanks, Nitin Madhok Clemson University CONFIDENTIALITY NOTICE This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you are not the intended recipient of this e-mail, any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by e-mail or telephone and permanently delete all copies of this e-mail and any attachments. > On Jan 29, 2018, at 1:42 AM, vinod bhaskaran > wrote: > > Hi, > > I am a new beginner in programming. > I saw a code (given below) to reverse string. > > newstring = '' > oldstring = 'Newton' > for char in oldstring: > newstring = char + newstring > print(newstring) > > > > Could someone explain how it is traversing to get the string reversed? > > As the new character is adding the char in the new string but how is it > getting reversed without any line giving the char number to be traversed in > reverse order. > > Thanks, > Vinod > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt in a program
Thanks a lot Nitin. I misunderstood the "char + newstring". As a newbie to programming as well as newbie to Python trying to grasp basics. Sure will need the built in functions present for different things in Python. Any suggestion good book for python? Thanks, Vinod Bhaskaran On Mon, Jan 29, 2018, 2:47 PM Nitin Madhok wrote: > Vinod, > > First time it loops, > newstring = ‘’ > oldstring = ‘Newton’ > char = ‘N’ > char + newstring = ‘N’ + ‘’ = ‘N’ > > Second time it loops, > newstring = ‘N’ > oldstring = ‘Newton’ > char = ‘e’ > char + newstring = ‘e’ +’N’ = ‘eN’ > > Third time it loops, > newstring = ‘eN’ > oldstring = ‘Newton’ > char = ‘w’ > char + newstring = ‘w’ +’eN’ = ‘weN’ > > Fourth time it loops, > newstring = ‘weN’ > oldstring = ‘Newton’ > char = ‘t’ > char + newstring = ‘t’ +’weN’ = ‘tweN’ > > Fifth time it loops, > newstring = ‘tweN’ > oldstring = ‘Newton’ > char = ‘o’ > char + newstring = ‘o’ +’tweN’ = ‘otweN’ > > Sixth/Final time it loops: > newstring = ‘otweN’ > oldstring = ‘Newton’ > char = ‘n’ > char + newstring = ‘n’ +’otweN’ = ‘notweN’ > > newstring after loop finishes will be ‘notweN’ which is the reverse of > ‘Newton’ > > Let me know if that explanation helps you understand it better. There are > built in functions to reverse a string that are more efficient than this > approach that you should be using to reverse a string. > > -- > > Thanks, > Nitin Madhok > Clemson University > > CONFIDENTIALITY NOTICE > This e-mail, and any attachments thereto, is intended only for use by the > addressee(s) named herein and may contain privileged and/or confidential > information. If you are not the intended recipient of this e-mail, any > dissemination, distribution or copying of this e-mail, and any attachments > thereto, is strictly prohibited. If you have received this e-mail in error, > please immediately notify the sender by e-mail or telephone and permanently > delete all copies of this e-mail and any attachments. > > > On Jan 29, 2018, at 1:42 AM, vinod bhaskaran > wrote: > > > > Hi, > > > > I am a new beginner in programming. > > I saw a code (given below) to reverse string. > > > > newstring = '' > > oldstring = 'Newton' > > for char in oldstring: > > newstring = char + newstring > > print(newstring) > > > > > > > > Could someone explain how it is traversing to get the string reversed? > > > > As the new character is adding the char in the new string but how is it > > getting reversed without any line giving the char number to be traversed > in > > reverse order. > > > > Thanks, > > Vinod > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doubt in a program
On 29 Jan 2018, at 7:42, vinod bhaskaran wrote: As the new character is adding the char in the new string but how is it getting reversed without any line giving the char number to be traversed in reverse order. You don't need that, think about this example newstring = '' oldstring = "Newton" now you go through each char in oldstring, so you get first N which you add to newstring and you get newstring = 'N' next char is 'e' and then you do 'e' + 'N' and get 'eN' newstring = 'eN' next char the same way newstring = 'weN' etc until you get 'notweN' Remember that the for-loop will step through each char in oldstring so when you come to the end the loop will stop. = jem ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Need help with reading and cleaning CSV files for a class
On 2018-01-28, Geoff Hancock wrote: > Good day- > I'm in a difficult situation. > I have been asked to help teach students how to clean up a CSV > file in Python. Can you give an example of the kind of thing you need to teach? It is malformed csv that has to be changed into well-formed? That's sounds like a fun and challenging problem. -- Neil Cerutti ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python GUI Grid like view with checkboxes in first column
Hi, I need some suggestions/help in showing large amount of data in grid like view with first column having checkboxes. Please see the image attached. How can i achieve this in Python GUI? [image: Inline image 1]http://oi39.tinypic.com/28vq6wn.jpg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python GUI Grid like view with checkboxes in first column
On 29/01/18 16:30, Dragan Mestrovik wrote: > I need some suggestions/help in showing large amount of data in grid like > view with first column having checkboxes. Please see the image attached. > How can i achieve this in Python GUI? > [image: Inline image 1]http://oi39.tinypic.com/28vq6wn.jpg The first thing I'd suggest is do not use Tkinter as the GUI. There are other GUI frameworks with a native grid or table control which will be much more suitable. Whether or not they can put a checkbox in the first column is something you will need to investigate. As an example the wxPython framework has a grid component, and it can use custom renderers so I suspect a checkbox would be one such. But for the details I'd ask on the wxPython mailing list. Other frameworks such as GTk and Qt probably have grids too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor