Re: [Tutor] is there an online exam or coarse i can take to get a certificate
Am Samstag, den 16.07.2005, 19:39 +0500 schrieb Mustafa Abbasi: > is there an online exam or coarse i can take to get a certificate in > python. > preferrably cheap and online because i live in pakistan and online > exams are my only hope. Not that I would know. Certification for a programming language is even less useful IMHO than for administration knowledge ;) Andreas signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Performance difference, ``in'' vs ``has_key()''
I'm going to be doing some work where I'll be doing existence testings on keys on about a million records where it may require multiple passes so I'm a bit concerned about the timing of these tests. Is there any significant performance difference between the tests, ``key in dictionary'' and ``dictionary.has_key(key)''? I would prefer using the ``key in'' because it's a bit easier to type, and can also be used with lists in addition to dictionaries. A related question is where's the trade-off between using ``in'' with a list, and a dictionary? I presume that using it with small hashes will be faster than dictionries since it doesn't have to calculate the hashes. Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC UUCP: camco!bill PO Box 820; 6641 E. Mercer Way FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 URL: http://www.celestial.com/ Government is the great fiction, through which everbody endeavors to live at the expense of everybody else. -- Frederic Bastiat ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
> Is there any significant performance difference between the > tests, ``key in dictionary'' and ``dictionary.has_key(key)''? > I would prefer using the ``key in'' because it's a bit easier to > type, and can also be used with lists in addition to dictionaries. Dunno about speed, but they do disassemble slightly differently: >>> import dis >>> a={1:2, 3:4} >>> def x(): ... if 3 in a: ... print "3 in" ... >>> def y(): ... if a.has_key(3): ... print "3 has" ... >>> dis.dis(x) 2 0 LOAD_CONST 1 (3) 3 LOAD_GLOBAL 0 (a) 6 COMPARE_OP 6 (in) 9 JUMP_IF_FALSE9 (to 21) 12 POP_TOP 3 13 LOAD_CONST 2 ('3 in') 16 PRINT_ITEM 17 PRINT_NEWLINE 18 JUMP_FORWARD 1 (to 22) >> 21 POP_TOP >> 22 LOAD_CONST 0 (None) 25 RETURN_VALUE >>> dis.dis(y) 2 0 LOAD_GLOBAL 0 (a) 3 LOAD_ATTR1 (has_key) 6 LOAD_CONST 1 (3) 9 CALL_FUNCTION1 12 JUMP_IF_FALSE9 (to 24) 15 POP_TOP 3 16 LOAD_CONST 2 ('3 has') 19 PRINT_ITEM 20 PRINT_NEWLINE 21 JUMP_FORWARD 1 (to 25) >> 24 POP_TOP >> 25 LOAD_CONST 0 (None) 28 RETURN_VALUE Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
Quoting Bill Campbell <[EMAIL PROTECTED]>: > I'm going to be doing some work where I'll be doing existence > testings on keys on about a million records where it may require > multiple passes so I'm a bit concerned about the timing of these > tests. If you're just doing existence testing, is it an option to use a set? (builtin to Python 2.4) I admit, I don't know how it performs. But it would seem the most appropriate of the builtin data structures. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
On Jul 17, 2005, at 20:18, Bill Campbell wrote: Is there any significant performance difference between the tests, ``key in dictionary'' and ``dictionary.has_key(key)''? I would prefer using the ``key in'' because it's a bit easier to type, and can also be used with lists in addition to dictionaries. While we're on that topic, is there a particular reason why 'in', in a dict context, searches the keys instead of doing the logical thing and searching the values? -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
Max Noel wrote: > [snip] > > > While we're on that topic, is there a particular reason why 'in', > in a dict context, searches the keys instead of doing the logical thing > and searching the values? animals = { 'cat': "a cuddly little mammal who likes to eat birds", 'dog': "man's best friend, also a mammal and which also can eat birds", 'parrot': "a bird, favoured by Monty Python"} What is more natural? if parrot in animals: or if "a bird, favoured by Monty Python" in animals: ... André ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
Am Montag, den 18.07.2005, 00:53 +0200 schrieb Max Noel: > On Jul 17, 2005, at 20:18, Bill Campbell wrote: > > > Is there any significant performance difference between the > > tests, ``key in dictionary'' and ``dictionary.has_key(key)''? > > I would prefer using the ``key in'' because it's a bit easier to > > type, and can also be used with lists in addition to dictionaries. > > While we're on that topic, is there a particular reason why > 'in', in a dict context, searches the keys instead of doing the > logical thing and searching the values? Well, sorry I consider key in dict to be more natural than value in dict. Actually, there are implementation aspects: key in dict is a hash lookup. value in dict is a slow iteration over an unsorted "list". The only way to have a quick value lookup in a dict is keeping a shadow dictionary with inverted keys and values. (And if it's not a bijective relationship you probably need value -> list of keys) Andreas signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
A short trial with timeit.py shows that k in d is faster than d.has_key(k) k in d is about as fast as hk(d), where hk = d.has_key So it seems both expressions are about the same, but the expression dict.has_key involves an additional dictionary lookup to fetch has_key. Andreas Am Sonntag, den 17.07.2005, 11:18 -0700 schrieb Bill Campbell: > I'm going to be doing some work where I'll be doing existence > testings on keys on about a million records where it may require > multiple passes so I'm a bit concerned about the timing of these > tests. > > Is there any significant performance difference between the > tests, ``key in dictionary'' and ``dictionary.has_key(key)''? > I would prefer using the ``key in'' because it's a bit easier to > type, and can also be used with lists in addition to dictionaries. > > A related question is where's the trade-off between using ``in'' > with a list, and a dictionary? I presume that using it with > small hashes will be faster than dictionries since it doesn't > have to calculate the hashes. > > Bill > -- > INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC > UUCP: camco!bill PO Box 820; 6641 E. Mercer Way > FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 > URL: http://www.celestial.com/ > > Government is the great fiction, through which everbody endeavors to > live at the expense of everybody else. -- Frederic Bastiat > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT, Tcl & Python
Am Samstag, den 16.07.2005, 01:19 -0700 schrieb Luis N: > Hi, > > I was wondering if someone knowledgeable of both Tcl and Python could > suggest whether it would be a good or a bad idea to write a Python/Tk > application, with the motive to rewrite the application in Tcl/Tk once > completed. My reason for considering this route is that I have never > written a single line of Tcl code nor coded a Tk application in the > past. My motivation is the greater ease of deployment across systems > that Tcl seems to offer, with Starkits and Starpacks, > http://www.equi4.com/starkit.html Tcl also appears useful to learn, > for writing scripts in tclsh, etc. Well, Tcl isn't really a "language". Or if it is, it's so "trivial" that it is usually explained without a BNF grammar. tclsh is basically a shell (like /bin/sh), which has been designed to be easily extendable with C functions. Tcl had only a string data type for most of it's life. (Other data types like integer where added only in the last years ;) ) Tcl is quite "cool" as a glue language, but implementing anything beyond 100-lines scripts is painful. OTOH it's certainly a good idea to learn Tcl (and it's C API). Andreas > > I've experimented with py2exe in the past, which seems fine for > Windows, although I have never tried py2app, and this approach seems > cumbersome. A typical GUI app is approximately 5 MB in python, > distributed as a collection of files in a folder, whereas a Tcl > Starpack is a compact 1 MB, distributed as a single file executable. > > Sincerely, > > > Luis > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT, Tcl & Python
Why do not do this entirely in Python ? Em Seg, 2005-07-18 às 02:00 +0200, Andreas Kostyrka escreveu: > Am Samstag, den 16.07.2005, 01:19 -0700 schrieb Luis N: > > Hi, > > > > I was wondering if someone knowledgeable of both Tcl and Python could > > suggest whether it would be a good or a bad idea to write a Python/Tk > > application, with the motive to rewrite the application in Tcl/Tk once > > completed. My reason for considering this route is that I have never > > written a single line of Tcl code nor coded a Tk application in the > > past. My motivation is the greater ease of deployment across systems > > that Tcl seems to offer, with Starkits and Starpacks, > > http://www.equi4.com/starkit.html Tcl also appears useful to learn, > > for writing scripts in tclsh, etc. > > Well, Tcl isn't really a "language". Or if it is, it's so "trivial" that > it is usually explained without a BNF grammar. > > tclsh is basically a shell (like /bin/sh), which has been designed to be > easily extendable with C functions. Tcl had only a string data type for > most of it's life. (Other data types like integer where added only in > the last years ;) ) > > Tcl is quite "cool" as a glue language, but implementing anything beyond > 100-lines scripts is painful. > > OTOH it's certainly a good idea to learn Tcl (and it's C API). > > Andreas > > > > > I've experimented with py2exe in the past, which seems fine for > > Windows, although I have never tried py2app, and this approach seems > > cumbersome. A typical GUI app is approximately 5 MB in python, > > distributed as a collection of files in a folder, whereas a Tcl > > Starpack is a compact 1 MB, distributed as a single file executable. > > > > Sincerely, > > > > > > Luis > > > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- [EMAIL PROTECTED] -> python >>> print "http://ralobao.blogspot.com"; http://ralobao.blogspot.com >>> import sys; sys.exit(0) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
Bill Campbell wrote: > I'm going to be doing some work where I'll be doing existence > testings on keys on about a million records where it may require > multiple passes so I'm a bit concerned about the timing of these > tests. > > Is there any significant performance difference between the > tests, ``key in dictionary'' and ``dictionary.has_key(key)''? > I would prefer using the ``key in'' because it's a bit easier to > type, and can also be used with lists in addition to dictionaries. Are you sure you have a problem? How long does it take to process 1000 records? The best way to answer these questions is with the timeit module running production code on production data. Second best is to use timeit on simple test cases. Third best (a distant contender) is to guess and ask other people their opinion. But since I am feeling lazy and not in a coding mood I will give you my opinion instead of showing you how to use timeit =:-0 I think 'key in dict' is faster than 'dict.has_key()' because it avoids the attribute lookup for has_key(). You can see that in Alan Munroe's post. Though if you are looking up keys in a loop you can hoist the lookup out of the loop with something like d = {} hk = d.has_key for i in someList: if hk(i): # do something if i is in d If you can write the code to use dict indexing and exception handling that may be faster than checking for the key, depending on how often the exception is raised. Finally, if you post a code snippet of what you are trying to do on comp.lang.python you will likely get many well-considered responses. The real experts in optimization hang out there. HTH Kent > > A related question is where's the trade-off between using ``in'' > with a list, and a dictionary? I presume that using it with > small hashes will be faster than dictionries since it doesn't > have to calculate the hashes. > > Bill > -- > INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC > UUCP: camco!bill PO Box 820; 6641 E. Mercer Way > FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 > URL: http://www.celestial.com/ > > Government is the great fiction, through which everbody endeavors to > live at the expense of everybody else. -- Frederic Bastiat > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Just finished creating Shape_Calc.
Hey all, Just finished shape_calc.py. If anyone is interested in going through the code, before I send it to my website, let me know. If no one answers this within a week, I post the zip file on my site. Nathan Pinno. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Lists
Thank you Danny, you guessed correctly, problem solved ! Kind Regards, Daniel Smith -Danny Yoo <[EMAIL PROTECTED]> wrote: -To: [EMAIL PROTECTED]From: Danny Yoo <[EMAIL PROTECTED]>Date: 07/15/2005 10:06PMcc: tutor@python.orgSubject: Re: [Tutor] Python Lists> I have created a class which has many "Nested list" attributes. When I> create a second instance of the class, the lists are not empty, and> already contain the same values as were held in the previous> instantiation. As a C/C++ programmer, this majes no semns to me at all.> Could someone please explain to me what I must do to avoid this effect.Hi Daniel,I'm not positive that this has to do with lists; do you mind showing us anexample of the kind of classes that you've been writing?As a wild guess, I think you may be doing something like this:##class Person: friends = [] name = None def __init__(self, name): self.name = name def add_friend(self, other): self.friends.append(other) def greet_all(self): for friend in self.friends: print "hi", friend def __str__(self): return self.name##This is a Person class that has class-scoped variables 'friends' and'name', and when we play around with this, we see some funny things goingon:##>>> j = Person('john')>>> p = Person('paul')>>> r = Person('ringo')>>> j.add_friend(p); j.add_friend(r)>>> s = Person('ikari shinji')>>> j.greet_all()hi paulhi ringo>>> s.greet_all()hi paulhi ringo##How does 's' have friends?All instances of Person will share the same 'friends' list here, so itwill seem that all people are in this big band of brothers and sisters.This is probably nice and communal, but it doesn't reflect the harsh,dog-eat-dog reality, the separation and angst between people and angst.The mistake is to have 'friends' be defined in class-scope, rather than ininstance scope.Let's add that isolation.##class Person: def __init__(self, name): self.friends = [] self.name = name def add_friend(self, other): self.friends.append(other) def greet_all(self): for friend in self.friends: print "hi", friend def __str__(self): return self.name##Here, each person is __init__()ed in the cold, dark world, alone andfriendless, with no friends, and only a name to distinguish themselvesfrom their brethren.##>>> j = Person('john')>>> p = Person('paul')>>> r = Person('ringo')>>> j.add_friend(p); j.add_friend(r)>>> s = Person('ikari shinji')>>> j.greet_all()hi paulhi ringo>>> s.greet_all()>>>##And now Shinji has no friends. Gosh, this is a depressing example.*grin*Since you have some experience in C++, you may find Mark Pilgrim's"Dive into Python" a useful resource:http://diveintopython.org/object_oriented_framework/defining_classes.htmlI hope this helps clear things up!___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] newbie help> audio IO + python
Hi I've been looking at lots of sites and checked out the docs, but can't find the info I am looking for to be able to detect audio input from my sound card. I want to use input from a mic plugged into my sound card to trigger events via pySerial.. (which has great docs) Any help/advice much appreciated! Thanks, KG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Just finished creating Shape_Calc.
Luke and all, Shape_calc helps you to find the area, perimeter, and other info about shapes. Simple enough. - Original Message - From: luke To: Nathan Pinno Sent: Sunday, July 17, 2005 9:42 PM Subject: Re: [Tutor] Just finished creating Shape_Calc. what does shape_calc do? -Luke - Original Message - From: Nathan Pinno To: tutor@python.org Sent: Sunday, July 17, 2005 9:57 PM Subject: [Tutor] Just finished creating Shape_Calc. Hey all, Just finished shape_calc.py. If anyone is interested in going through the code, before I send it to my website, let me know. If no one answers this within a week, I post the zip file on my site. Nathan Pinno. ___Tutor maillist - Tutor@python.orghttp://mail.pythonorg/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT, Tcl & Python
> Tcl is a fun language with a wholeheap of interesting concepts new to > Python programmers. So its definitely worth looking at - and its nearly > always more compact than Python too. Alan Greenspun, author of one of my favorite web-development books "Philip and Alex's Guide to Web Publishing", also has written a nice Tcl/Tk tutorial: http://philip.greenspun.com/tcl/ If anything, the hilarious picture of a "Tickle Me Elmo" doll on the side makes it worth visiting. *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] regular expressions
Hello Using regular expressions how do I represent Floats. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is there an online exam or coarse i can take to get a certificate
On Sun, 17 Jul 2005, Andreas Kostyrka wrote: > Am Samstag, den 16.07.2005, 19:39 +0500 schrieb Mustafa Abbasi: > > is there an online exam or coarse i can take to get a certificate in > > python. preferrably cheap and online because i live in pakistan and > > online exams are my only hope. > > Not that I would know. Certification for a programming language is even > less useful IMHO than for administration knowledge ;) As a warning, the general feeling among the open source community seems be be that most certificate programs are useless. For example: http://wingware.com/pipermail/marketing-python/2002-February/003790.html is anecdotal, but does reflect the popular sentiment that someone who has a portfolio of real programming projects at hand can show more promise that who who only has a certificate. I don't believe there is a consensus yet on a strong, legitimate accreditation program. Most of us on the list probably don't know too much about formal certification, as many of us here are volunteers. But I suspect that any of the professional organizations (IEEE, ACM) should be able to help you in this; try contacting your local engineering groups. You may also want to ask your question on the main comp.lang.python newsgroup. Wait, I see that you may have done this already: http://aspn.activestate.com/ASPN/Mail/Message/python-list/2744017 Ok, hopefully you should be able to get some answers from there too. Good luck to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Performance difference, ``in'' vs ``has_key()''
> A related question is where's the trade-off between using ``in'' with a > list, and a dictionary? I presume that using it with small hashes will > be faster than dictionries since it doesn't have to calculate the > hashes. Hi Bill, Scanning for an elements in a list is a "linear" operation, in the sense that the time it takes to search is proportional to the size of the list. (Big list == big search time.) Dictionaries have a lookup time that will probably be a constant-time operation, regardless of the size of the collection. (Big dictionary == probably doesn't matter. *grin*) This doesn't mean that dictionaries are always faster than lists: as you know, calculating hash values can take time. But the cost of hashing is usually negligible, since many of Python primitive data types (like strings) automatically cache their hash values too! There's always a possibility, however remote, that the hash function is hideous on the kind of data that you're using. However, Python's Dictionary implementation has been battle-tested and tuned well, so it's probably not a mistake to use dictionaries if they seem like the appropriate data structure. A good book in algorithms will almost always cover the performance characteristics of those two strategies; there are also a lot of good resources on the web about them. NIST has two articles on those two: http://www.nist.gov/dads/HTML/linearSearch.html http://www.nist.gov/dads/HTML/hashtab.html and the excellent Wikipedia has nice readable articles: http://en.wikipedia.org/wiki/Linear_search http://en.wikipedia.org/wiki/Hashtable http://en.wikipedia.org/wiki/Category:Search_algorithms Good luck to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regular expressions
On Sun, 17 Jul 2005, Servando Garcia wrote: > Using regular expressions how do I represent Floats. Hi Servando, I know that you're working on a parser project, but the regex for doing floats is pretty much a homework project. There's not much we can do except point you toward the Regular Expression HOWTO tutorial page: http://www.amk.ca/python/howto/regex/ I'd also strongly recommend that you look at the documentation in the Python Standard Library, as it does have concrete examples on how to recognize things like floats here: http://www.python.org/doc/lib/node117.html Your question is also context-sensitive: what a floating point number looks like really depends on what kind of language we're modeling. As a concrete example, in the ML family of languages: .42 is not a floating-point literal, although it is one in Python, because it's missing a leading decimal digit. Conversely, in the Ruby language, 123_456.789 is a floating point literal, although it isn't one in Python, because Python doesn't allow underscores. I guess I'm trying to say: some lexical conventions are not universal: otherwise, things would be too easy. *grin* You can't assume that everyone uses the same notation for floating point literals: you need to show examples of what you consider to be floats. If you want to see Python's specification for floating point literals, see: http://www.python.org/doc/ref/floating.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] I am going to change Giant Calculator into mini calculators.
Hey all, The subject says it all. If anyone is interested in working on Giant Calculator, give me a shout, and I'll send you a ZIP file with the PY file. Nathan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor