Re: [Tutor] Final review

2014-05-07 Thread Danny Yoo
On Wed, May 7, 2014 at 8:49 PM, Scott W Dunning wrote: > > On May 5, 2014, at 10:13 PM, meenu ravi wrote: > >> Likewise, the index of d, which is the last word in the word "Hello world" >> is 10. >> >> So, the maximum index you can access in the word "Hello world" is 10. But >> when you try to

Re: [Tutor] Final review

2014-05-07 Thread Scott W Dunning
On May 5, 2014, at 10:13 PM, meenu ravi wrote: > Likewise, the index of d, which is the last word in the word "Hello world" is > 10. > > So, the maximum index you can access in the word "Hello world" is 10. But > when you try to give the command, > > >>> greeting [len(greeting)] > > It is t

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread Alan Gauld
On 08/05/14 01:42, C Smith wrote: I guess intuiting efficiency doesn't work in Python because it is such high-level? Or is there much more going on there? Efficiency is usually language independent because its the algorithm, or design, that determines efficiency in most cases. Your example i

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread Brian van den Broek
On May 7, 2014 8:42 PM, "C Smith" wrote: > > I guess intuiting efficiency doesn't work in Python because it is such > high-level? Or is there much more going on there? Hi, The level is a good part, yes. If, like me, you don't know what C constructs are under python constructs, you are guessing

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread C Smith
I guess intuiting efficiency doesn't work in Python because it is such high-level? Or is there much more going on there? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread Alex Kleider
On 2014-05-07 16:27, C Smith wrote: #sum all even fib seq integers under 4 million fibs = [1,2] sum = 0 while fibs[-1] < 400: nexty = fibs[-1] + fibs[-2] fibs.append(nexty) for xer in fibs: if xer%2 == 0: sum += xer print sum This gets the correct solution, but what wou

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread C Smith
I see. Thanks that is exactly what I was looking for. Would your example be an instance of an object-oriented approach, compartmentalizing things into functions? On Wed, May 7, 2014 at 7:55 PM, Joe Cortes wrote: > Welcome to the wonderful world of generators! > > Looking at your code, you'll noti

Re: [Tutor] How inefficient is this code?

2014-05-07 Thread Brian van den Broek
On May 7, 2014 7:30 PM, "C Smith" wrote: > Someone suggested projecteuler.net and I started blazing through > things I had done before, when I realized this would be a good time to > start more efficient practices instead of code that just happens to > work and may be very inefficient. > > #sum

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Steven D'Aprano
On Wed, May 07, 2014 at 06:43:11PM +0530, jitendra gupta wrote: > Hi > > I just want to create a new xm file from existing xml file. so basically i > want to put contry details in countryName.xml from these file. > > I thought to do via read a line by line with normal file handling. but > there a

[Tutor] How inefficient is this code?

2014-05-07 Thread C Smith
A topic came up on slashdot concerning "intermediate" programming, where the poster expressed the feeling that the easy stuff is too easy and the hard stuff is too hard. Someone did point out that 'intermediate' programming would still involve actually selling code or at least some professional ex

Re: [Tutor] Final review

2014-05-07 Thread Steven D'Aprano
On Tue, May 06, 2014 at 06:36:21PM +0100, Alan Gauld wrote: > Aside: > len() does work with range() and slicing so you can write > > myList[:len(mylist)] > > to get a copy of your list... Even easier is a blank slice. The start defaults to zero, the end to the length of the sequence, and the s

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Danny Yoo
To elaborate: from xml.dom.pulldom import START_ELEMENT, parse import io sampleData = u""" 2 2008 141100 5 2011 59900 69 20

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Danny Yoo
On Wed, May 7, 2014 at 1:26 PM, jitendra gupta wrote: > I cant use etree/SAX because there we cant get complete line , of course we > can get it by tag name but we are not sure about tag also. Only we know > what ever child of we need to put in new file with country name. Why can't you use su

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Neil D. Cerutti
On 5/7/2014 3:49 PM, Stefan Behnel wrote:> Neil D. Cerutti, 07.05.2014 20:04: >> In my own personal case, I partly prefer xml.sax simply because it ignores >> namespaces, a nice benefit in my cases. I wish I could make ElementTree do >> that. > > The downside of namespace unaware parsing is tha

Re: [Tutor] xml parsing from xml

2014-05-07 Thread jitendra gupta
no only XML (Complex) On Thu, May 8, 2014 at 1:51 AM, Danny Yoo wrote: > On Wed, May 7, 2014 at 6:13 AM, jitendra gupta > wrote: > > > I just want to create a new xm file from existing xml file. so basically > i > > want to put contry details in countryName.xml from these file. > > > > Side que

Re: [Tutor] xml parsing from xml

2014-05-07 Thread jitendra gupta
@All thanks, I cant use etree/SAX because there we cant get complete line , of course we can get it by tag name but we are not sure about tag also. Only we know what ever child of we need to put in new file with country name. Note: File size is around 800MB, for other requirement(Like converti

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Danny Yoo
On Wed, May 7, 2014 at 6:13 AM, jitendra gupta wrote: > I just want to create a new xm file from existing xml file. so basically i > want to put contry details in countryName.xml from these file. Side question: does your input have to be XML, or can it be in a simpler format such as JSON?

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Stefan Behnel
Neil D. Cerutti, 07.05.2014 20:04: > On 5/7/2014 1:39 PM, Alan Gauld wrote: >> On 07/05/14 17:56, Stefan Behnel wrote: >>> Alan Gauld, 07.05.2014 18:11: and ElementTree (aka etree). The documenation gives examples of both. sax is easiest and fastest for simple XML in big files ... >>> >>>

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Neil D. Cerutti
On 5/7/2014 1:39 PM, Alan Gauld wrote: On 07/05/14 17:56, Stefan Behnel wrote: Alan Gauld, 07.05.2014 18:11: and ElementTree (aka etree). The documenation gives examples of both. sax is easiest and fastest for simple XML in big files ... I wouldn't say that SAX qualifies as "easiest". Sure,

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Alan Gauld
On 07/05/14 17:56, Stefan Behnel wrote: Alan Gauld, 07.05.2014 18:11: and ElementTree (aka etree). The documenation gives examples of both. sax is easiest and fastest for simple XML in big files ... I wouldn't say that SAX qualifies as "easiest". Sure, if the task is something like "count nu

Re: [Tutor] Useful blog post: How to debug small programs

2014-05-07 Thread Jerry Hill
On Wed, May 7, 2014 at 6:50 AM, Walter Prins wrote: > Hi all, > > I stumbled across this post today and thought it was worth sharing > with the Python tutor list. It provides good advice to students about > debugging your programs and how to ask for help on forums, in > particular Stack overflow,

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Stefan Behnel
Alan Gauld, 07.05.2014 18:11: > Python comes with several XML parsers. The simplest to use are probably sax > and ElementTree (aka etree). The documenation gives examples of both. sax > is easiest and fastest for simple XML in big files while etree is probably > better for more complex XML structur

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Alan Gauld
On 07/05/14 14:13, jitendra gupta wrote: I thought to do via read a line by line with normal file handling. but there a problem with that. So i want to handle python XML . Could you please suggest on this. Python comes with several XML parsers. The simplest to use are probably sax and Element

Re: [Tutor] xml parsing from xml

2014-05-07 Thread Neil D. Cerutti
On 5/7/2014 9:13 AM, jitendra gupta wrote: Hi I just want to create a new xm file from existing xml file. so basically i want to put contry details in countryName.xml from these file. I thought to do via read a line by line with normal file handling. but there a problem with that. So i want to

[Tutor] xml parsing from xml

2014-05-07 Thread jitendra gupta
Hi I just want to create a new xm file from existing xml file. so basically i want to put contry details in countryName.xml from these file. I thought to do via read a line by line with normal file handling. but there a problem with that. So i want to handle python XML . Could you please suggest

[Tutor] Useful blog post: How to debug small programs

2014-05-07 Thread Walter Prins
Hi all, I stumbled across this post today and thought it was worth sharing with the Python tutor list. It provides good advice to students about debugging your programs and how to ask for help on forums, in particular Stack overflow, but in that way equally applies to the Python tutor list. Link