Re: [BangPypers] Django - Infinte Loop
1. Why are you doing this using a signal? Signals are best used when saving of Model1 needs to trigger some action on Model2. If you want to modify Model1 itself, you're better off doing this inside MyModel::save 2. If you really want to do it this way, put an if condition in my_func so that instance.save() is called only the first time. It is hard to give details without knowing the reason why you're doing this. But something like this would work: def my_func(sender, instance, created, **kwargs): if instance.status == 'task completed': return # do something instance.status = 'task completed' instance.save() Or even something like this: def my_func(sender, instance, created, **kwargs): try: if instance.in_signal: return except AttributeError: instance.in_signal = True # do something instance.status = 'task completed' instance.save() Anand Reddy Pandikunta anand21na...@gmail.com writes: Hi, *models.py* *def my_func(sender, instance, created, **kwargs):* * # do something* * instance.status = 'task completed'* * instance.save()* *class MyModel(models.Model):* * status = models.CharField(max_length=100, blank=True)* * # some code* *signals.post_save.connect(my_func, sender=MyModel)* I am using post_save signal to connect to a function. If a new instance of model is saved, post_save signal connects to my_func. Once the function is executed, I am updating status of the model. This is again sending post_save signal which is leading to infinite loop. I want to execute my_func only once and update status many times. Does any one know how to do this? -- - Anand Reddy Pandikunta www.avilpage.com www.quotes160.com ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Multiple return values from a function : Where to draw the line ?
Mandar Vaze / मंदार वझे mandarv...@gmail.com writes: Code 1: ... return dict(fname=fname, lname=lname, saluation=salutation, gender=gender, addr1=addr1, addr2=addr2, city=city, state=state, country=country) First of all, both functions are returning a single value, a single dict. So the entire discussion of how many values should I return from a function is irrelevant. As for which of the two code samples is better, I think it is a matter of taste. However, I should point out that in template programming (as happens in the case of Django), it is fairly common to create and return a dict containing all the values that are needed for the template. In other words, it is a pattern that people are used to; and since they're all values that are needed in the same template, it is OK to club them together like this. To me, Code #1 is perfectly acceptable - for this use case. Code 2: user = {} [ 5 more citation lines. Click/Enter to show. ] user['fname'] = fname user['lname'] = lname ... ... ... user['country'] = country return dict(user=user) I don't see why doing the dict assignments into different statements is any better than simply creating the dict directly. In fact, I prefer the former (but, I would put each key: value pair on a line by itself), because the intent is much clearer. Also, you could have done return user here instead of return dict(user=user). Which one is better has nothing to do with python, and depends upon the template language you're using and the content of the template. navin. ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] First python interview
If I were interviewing you, I would not really be checking your python knowledge (unless you claimed to be good in Python in your resume). I would really check how good you are in Java (your primary language), and your general programming and problem solving skills. However, if I really wanted someone good in Python right now, I would check how far you had progressed in writing 'pythonic' code. Here is one attempt at making a list of features that newbies (i.e. people migrating to python from other languages) typically miss, or learn late in life. - List comprehensions and generators. - Familiarity with the standard library - too much re-invention of the wheel exists in the world today. You shouldn't be adding to that problem. - Use of *args and **kwargs - knowledge of itertools - Docstrings and Doctests - scipy/numpy/matplotlib if you're doing anything with data Even more advanced features - I really wouldn't expect you to know these, but if you did, that would impress me: - Generator expressions (and how to create those yourself). Combine with list comprehensions - Decorators - to make your code concise and more readable. And learn to create decorators - Understanding of python closures. A lot of complex code gets written by people who don't think of using an appropriate closure - The 'with' statement. - Properties. I adapted this from here: http://www.quora.com/Navin-Kabra/answers/Python-programming-language-1 Also check out this StackOverflow question: http://stackoverflow.com/questions/101268/hidden-features-of-python Avneesh Chadha avneesh.cha...@gmail.com writes: Hi guys, I am going in for my first python interview. I have never actively worked in python(java programmer) but am comfortable with it to some extent(used it for competing at code chef). I am sure all you python gurus probably would have interviewed people for python and many of you would have given lots of interviews for Python. I could really use some tips on what exactly should I really be focusing on while studying for it and what should I expect. A little about the process up till now- They sent me a problem to solve(the usual code jam type problem, but toned down in difficulty) which i was able to do correctly. Now i have telephonic interview. They basically require people strong in python and knowledge of django is a plus. I have 2 days to prepare for it. Thanks. ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] [Novice] Question on File seek and tell methods
The way I would do this is as follows: I would use itertools to make the code more concise. Also, a strong recommendation that `with` should be used whenever you want to open a file. And use of the `print_function` from `__future__` for python-3 compatibility. from __future__ import print_function from itertools import dropwhile with open('/tmp/foo.txt') as f: for line in dropwhile(lambda l: not l.startswith('Chennai'), f): # process line here print(line.strip()) if line.startswith('Angry Birds'): break Note: there is also `takewhile` in itertools that could have been useful if the 'Angry Birds' line is not to be included in the selected lines. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Python dictionaries, deleting elements while iterating.
Anand Chitipothu anandol...@gmail.com writes: loop. In Python 3, it can be written as a dictionary-comprehension. Dictionary and set comprehensions are also available in Python 2.7 ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] python framework for android
On Wed, Jan 4, 2012 at 11:37 AM, Kenneth Gonsalves law...@gmail.com wrote: can anyone recommend a python framework for android? Negative vote for SL4A (previously known as ASE - Android Scripting Environment). I have played with it, and I think it is largely a toy - it is good for personal use - quick scripts for automating things you like to do, but not useful for anything serious. Also, I haven't found anything else that allows Python programming for Android and could be used in developing serious apps. Might be forced to use Java or JavaScript :-( ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] ElementTree object instance evaluates to False?
On Tue, Dec 6, 2011 at 9:49 AM, Vikas BN vikas...@gmail.com wrote: I'm working on a script to parse XML files and am using cElementTree for the same. However, I was under the impression that anything that's a None type or 0 or would evaluate to False and the rest would be True (incl an instance of an object). Any object that has a __len__ defined will evaulate to False in a boolean context if __len__ returns 0. (See also __nonzero__). See section 5.1 here: http://docs.python.org/library/stdtypes.html I hope this answers your question. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] continue in try..except
On Sat, Nov 19, 2011 at 8:31 PM, Nikunj Badjatya nikunjbadja...@gmail.comwrote: Can someone throw some light on this please. If I understand right, this is what you want to do: Somewhere deep inside the main function, an exception is thrown. In the exception handler, if some condition is true, you want to say, no, no, don't worry about the exception. please continue execution of main from the line after the exception. I don't think this can be done in python. You'll need to restructure your code instead. On Fri, Nov 18, 2011 at 7:23 PM, nikunj.badja...@emc.com wrote: Hi , Please look at the below code snippet: {{{ if __name__ == __main__: try: main() except KeyboardInterrupt: print(\nKeyboard interrupt from the user !!) ret = input(Want to abort the installation ?[y/n]: ) while True: if ret == y: sys.exit(0) elif ret == n: ## Want to continue the main() where it left of. else: ret = input(Please enter either y/n : ) continue }}} In the elif block. I want to have a provision wherein main() would continue its execution where it left off. How can this be done.? Thanks Nikunj ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] if not with comparision statement in python
On Sat, Jul 30, 2011 at 1:13 PM, Asif Jamadar asif.jama...@rezayat.net wrote: if not minimum=actual_result and not maximum=actual_result: How to check if actual result is not laying between minimum value and maximum value. if not minimum = actual_result = maximum: ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] [OT] getting a business email vendor
On Thu, Jun 30, 2011 at 11:57 AM, Vishal vsapr...@gmail.com wrote: We would like to have a *good* business email vendor, and hosting for our website. Would like to know the ones you have found to be good in *India*. Try Mithi Software (http://www.mithi.com/) a Pune-based company. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Nice feature
With Python 2.6.5 (on ubuntu) I get even more bizarre behavior: foo=(1,[2,3,4]) foo[1]+=6 Traceback (most recent call last): File stdin, line 1, in module TypeError: 'int' object is not iterable foo (1, [8, 9, 10]) On Fri, Apr 1, 2011 at 6:17 PM, Noufal Ibrahim nou...@gmail.com wrote: Came across this at PyCon. Comments? foo = (1,[2,3,4]) foo[1] += [6] Traceback (most recent call last): File stdin, line 1, in module TypeError: 'tuple' object does not support item assignment foo (1, [2, 3, 4, 6]) -- ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Fwd: Help with Python IDE's
On Mon, Mar 28, 2011 at 9:18 AM, Gora Mohanty g...@mimirtech.com wrote: Most any IDE that one is using, and that handles Python should work. Personally, I use emacs with various modes for Django development. Can you share exactly which modes you're using for django developement. I use python-mode.el and while it works reasonably well for python, I haven't managed to make it work for django (it does not autocomplete for django). Also, any other tips/tricks you can share would help. Thanks. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] issues using constructor in unittest
On Mon, Mar 14, 2011 at 1:56 PM, Nitin Kumar nitin.n...@gmail.com wrote: See below small example. I am trying to have one constructor for a class with unittest inherited. Avoid overriding the constructor of TestCase. That is not recommended. self.x = 3 Put this is setUp instead of the constructor *unittest2.TestCase.__init__(self) If you must do this, the correct way of doing it is: def __init__(self, *args, **kwargs): super(XMLSupport, self).__init__(*args, **kwargs) self.x = 3 ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Proposed python module: simpleoauth
On Thu, Mar 10, 2011 at 12:32 PM, Baishampayan Ghose b.gh...@gmail.comwrote: Where is the code? simpleoauth/__init__.py seems to have only one line - /home/navin/d/hacks/python/oauth/simple_oauth.py Aargh... sorry. Checked in from the wrong directory. It should be fixed now. (Deleted and re-created the repo, so if you had cloned earlier you'll want to delete it and reclone the whole thing.) Thanks for the heads up BG. navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
[BangPypers] Proposed python module: simpleoauth
Hi All, Need your help on this. After getting very confused and frustrated at the state of OAuth libraries in python, I decided that there needs to be a simpler way of doing OAuth in Python. As a proof-of-concept I've implemented the following: https://github.com/ngkabra/simpleoauth The design goals were: - Simple interface for the common cases, at the expense of flexibility - Should work with OAuth v1 or OAuth v2 with the same or similar interface - Should be easy to incorporate into Django At this stage, this code is neither complete nor is it well tested. It is just a proof-of-concept that works for basic cases (I've tried it with facebook and twitter). Help needed: - Feedback on whether this seems useful. Note: this is not targeted towards OAuth ninjas, and is not appropriate for complex OAuth implementations. Just a quick way to access basic OAuth based APIs like facebook, twitter, yammer, delicious. - If it seems useful, then help needed in completing it - with finishing the functionality, packaging, testing etc. Let me know what you think. Thanks. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] [JOB] Python developer required in Pune with web development experience
On Thu, Jan 13, 2011 at 11:44 AM, Kenneth Gonsalves law...@au-kbc.orgwrote: or a way of saying: 'there is going to be bargaining here'? I think it's a way of saying: Salary will depend upon who you are, how much experience you have, what your current salary is, and how desperately we need you. The reality is that for the same job posting, I can get a candidate who is expecting Rs. 5L, and I can get another expecting Rs. 15L. Now supposed I had a specific role in mind, and a salary range of Rs 9L to 11L in mind for that role. If the 5L or 15L candidates are any good, most likely I will create a new role which fits their capabilities and will offer them a salary accordingly - which will be very different from the original salary and the original role. And everybody wins. Mentioning a salary range is unnecessarily cutting off options. navin. What I don't understand is people who don't mention prices of their product offerings - where the products are fairly standard. (e.g. training, workshop etc.) ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] regular expression for Indian landline numbers
On Fri, Nov 26, 2010 at 9:03 AM, Dhananjay Nene dhananjay.n...@gmail.comwrote: Thus there could be the optional prefixes +91 or 0 followed by an additional sequence of numbers which may have embedded some spaces, hyphens or in rare cases parenthesis which are quite ignorable. So all one really needs to do (say if one wants to call back) is to extract one single 10 digit number using the above logic by stripping off the optional prefixes and the extra characters (which I presume would be quite trivial). But then maybe my mind is not working well today early morning :) This might be veering off from the original subject a bit, but since you brought it up, here's the code I use for extracting an Indian phone number from various different ways in which users might enter that...: http://pastebin.com/GRyLgePr No, it's not an regexp like Kenneth wants. But I've found this piece of code to be useful in a number of different contexts... ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Django-based CMS recommendations?
On Thu, Nov 25, 2010 at 12:34 AM, Venkatraman S venka...@gmail.com wrote: Let me give you a word of caution : Pinax is a monster and sometimes cane make you go mad. By monster , i dont mean the hugeness, but how sometimes certain customizing aspects of it can cause involuntary hair loss. But, Pinax is a great solution when you want to do anything 'social' quickly. I agree with Venkat. Pinax is good if you want only what comes out of the box. I would really not recommend it if you want to make your own customizations. It has not yet reached the stage where (unlike Django) you can do customizations without touching the base Pinax code. Pinax is not yet at 1.x and that shows. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] string to list query
On Thu, Aug 5, 2010 at 10:07 AM, Vikram K kpguy1...@gmail.com wrote: Suppose i have this string: z = 'AT/CG' How do i get this list: zlist = ['A','T/C','G'] This is a very poorly specified question. And in absence of any information about what exactly are the constraints on the input, and what is the difficulty you're trying to overcome (and indeed no information about what you tried already), I am going with the simplest solution: zlist = [z[0:1], z[1:4], z[4:5]] It looks like you're doing some DNA analysis, and I would guess that all these strings will be 5 characters, I'm sure my solution will work fine. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] list problem
I suggest that in such cases, avoid the temptation to do something clever. If it was difficult for you to write the code, it will be even more difficult to read and understand it. Unless there is a very good reason, write the simplest, most braindead code. xdictstart={} xdictend={} for item in sorted(x): xdictend[item[0]] = item[1] if not item[0] in xdictstart xdictstart[item[0]] = item[1] On Thu, Jul 22, 2010 at 3:21 PM, Vikram kp...@rediffmail.com wrote: Suppose you have the following list: x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]] My problem is that i wish to obtain the following two dictionaries: xdictstart = {'cat':10, 'dog':1} xdictend = {'cat':30, 'dog':5} Any nice way to do the above? Thanks. --- Those interested in the above problem may consider the following code (which does not actually do what i want): xdictend = dict(x) xdictend {'dog': 3, 'cat': 30} x [['cat', 10], ['cat', 20], ['cat', 30], ['dog', 5], ['dog', 1], ['dog', 3]] xdictstart = {} map(xdictstart.setdefault, *zip(*x)) [10, 10, 10, 5, 5, 5] xdictstart {'dog': 5, 'cat': 10} ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] sorting of list
On Fri, Jun 25, 2010 at 1:18 AM, Vikram kp...@rediffmail.com wrote: Suppose i have this: z1 = [[34,44,'1011'],[40,60,'1011'],[50,50,'1013'],[40,20,'1011'],[10,30,'1013']] how do i sort the nested list z1 so as to obtain: bla = [[34,44,'1011'],[40,20,'1011'],[40,60,'1011'],[10,30,'1013'],[50,50,'1013']] It appears that you want to sort by the 3rd, then 1st and then 2nd element of each sublist. This is how you could do it: z1.sort(key=lambda x: (x[2],x[0],x[1])) print z1 OR sorted(z1,key=lambda x: (x[2],x[0],x[1])) ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Regarding Python popularity
On Mon, Feb 8, 2010 at 4:58 PM, Shashwat Anand anand.shash...@gmail.comwrote: Mine one of senior (at Amazon) suggested me Go learn C++/ Java and improve your DS/ Algo/ OS/OOP skills On the other hand, I would like to point out that to really, really improve your DS/Algo skills (two of the most important skills for a CS graduate, IMO), python is a great language. You can learn, and prototype, and experiment much faster than if you were to try the same thing in Java/C/C++ or (oh the horror!) PHP. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] which one is the best pythonic way .
On Tue, Feb 9, 2010 at 10:22 AM, Srinivas Reddy Thatiparthy srinivas_thatipar...@akebonosoft.com wrote: 1.sum([i for i in range(1000) if i%3==0 or i%5==0]) Slightly better would be: sum((i for i in range(1000) if i%3==0 or i%5==0)) 2.gen=(i for i in range(1000)) sum([i for i in gen if i%3==0 or i%5==0]) What I gave above is a better way of doing this 3.sum(filter(lambda a:a%3==0 or a%5==0,range(1000))) avoid lambda's whenever possible. they are difficult to understand, and can be avoided in most cases. Even Guido dislikes them. 4.def generator(m): count=0 while countm: if count%3==0 or count%5==0: yield count count+=1 sum([i for i in generator(1000)]) Overkill. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Tuples vs Lists, perfromance difference
On Thu, Dec 24, 2009 at 1:05 PM, Senthil Kumaran orsent...@gmail.comwrote: Also interesting stuff about the Java comparison. The question remains, why the JVM is so fast and why Python is not as far as JVM? I am sure there must be a ton of info on this over the net :) Java is statically typed. Which means that the compiler (and the JIT compiler) has lots of information available to it. Lots of bindings can be done at compile time. Lots of optimizations can be done at compile time. And even more optimizations can be made at runtime. Much of that is just not possible in Python. No amount of compiler improvements and optimizations can change this. navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Tuples vs Lists, perfromance difference
On Wed, Dec 23, 2009 at 9:03 PM, Senthil Kumaran orsent...@gmail.comwrote: On Wed, Dec 23, 2009 at 11:15:56AM +0530, Vishal wrote: After having everything in Python now, performance is something people want to look at. Hence these efforts. Would you like to explain a bit more on this? Most often with Python when I have found people speaking about performance and speed, it has been associated either with incorrect expectations or some kind of design mistakes which most of us do when we are beginning. Well said. On an average, a program in a dynamic programming language, if it is CPU bound, is likely to be 10 times slower than one in a static language (like C/C++ or Java). But, programming in python is still acceptable because: 1. Most programs in the world are IO bound (i.e. file IO, database IO or network IO) 2. Most programs don't really need the speed. If #1 is your problem (as is likely), you need to look at the structure and organization of your program to ensure more efficiency of the IOs. This has nothing really to do with python, or lists and tuples, and whether a for loop is faster than a list comprehension. Your question on tuples vs lists is very corner case with respect to performance. It should hardly matter for most programs. If it did matter to you, I would like to know. Agreed. If you find yourself worrying about the performance of lists vs tuples in a python program, in 90% of the cases, I would think that something is significantly wrong with the picture. If this is indeed an important issue to worry about, even I would love to know that use case and discuss it. Also, when I mentioned about expectations, it is clearly wrong for us to expect the performance of C++ in Python. A good comparison should be Java and I have found interchanging performance differences for applications in Java and Python. Huh!? I think you phenomenally misunderstand the current state of Java. Performance of Java and C/C++ is likely to be very comparable to each other (even in case of CPU bound programs). By contrast, a dynamic programming language like php/python/ruby is likely to be 10x slower then either of them. See http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/for a datapoint and a more detailed discussion. navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Tuples vs Lists, perfromance difference
On Thu, Dec 24, 2009 at 7:39 AM, Senthil Kumaran orsent...@gmail.comwrote: Here is the link: http://shootout.alioth.debian.org/ There are three Java states given, Java -xint, Java steady state and Java -server. Try choosing each of them and compare against Python and C++. With respect to Python, you will find the alternative differences in with java -xint and java -server and while java steady state will always be faster ( I think, the java steady stage ignores the loading of the virtual machine). Actually, steady state is more about ensuring that the JIT compiler has had time to kick in. I think in most cases steady state is the most useful one to compare against. In real life, you're typically concerned about performance in long running programs (i.e. seconds as opposed to milliseconds - otherwise why are you bothered?) and in that case, the JVM would be in steady state for most of the time. But all of them will slower when compared to C++. Yeah, it is right to expect that JVM based will be slower than compiled C++ code. Is it not? Nope. With JIT compilation, a JVM can actually beat C++ Overall, though, from the shootout page, it looks like Java is comparable to C/C++ in many cases, and a little slower in some cases. Python, on the other hand, is 10x to 30x slower in most cases... So my point still stands navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] mobile application development
I might add that you can't code in Python on the Android, since it runs only Java apps. I heard there are efforts to bring X language apps into Android, but none is yet mature. You can code in python http://code.google.com/p/android-scripting/wiki/PythonAndroidAPI (but agreed, that it's probably not very mature) navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] How to search a word list very fast
Amit, Question: why do you want to build this yourself? Depending on what exactly you want to do, it is quite likely that there already exists an algorithm or a free service that does this for you. You should search for that... On Fri, Oct 30, 2009 at 11:37 AM, Amit Sethi amit.pureene...@gmail.comwrote: Hi, I am trying to develop a sort of keyword generator for blog posts much like the Yahoo Keyword service . As an initial idea I am using the list of most used 3000 words in project Gutenberg as being redundant . My question is what is the best way to organize my data and what algorithms would allow me to search this list the fastest. I am sorry for asking a very algorithmic question on the list but I don't know where I can ask my more algorithmic problems suggestions on that would be great Thanks -- A-M-I-T S|S ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] some doubts regarding python
Something like this should work: def lcm2(a, b): return a*b/fractions.gcd(a,b) def lcm(mylist): return reduce(lcm2, mylist) Actually, this probably should be reduce(lcm2, mylist, 1) navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] New to python - neuron ring
On Mon, Oct 12, 2009 at 12:49 PM, Gopinath R gopiindia...@gmail.com wrote: I am a newbie to python. i like to learn python strongly. which version is recommended to start with 2.6 or 3.0. I believe 3.0 has lot more features added, there is no backward compatibility in that. we cannot use some of the 2.6 syntaxes in that. for Example: raw_input. it worries me a lot. pls give some suggestion. I think one of the important features of python is the availability of a huge set of external libraries that make your programming easier (because you can reuse stuff, and not reinvent the wheel). This is true of python 2.6, but not yet true of python 3.x. So, assuming that you would like to make something useful with python (as opposed to toy programs), go with 2.6. I can't think of a strong reason for navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] New to python - neuron ring
On Mon, Oct 12, 2009 at 1:14 PM, Navin Kabra navin.ka...@gmail.com wrote: On Mon, Oct 12, 2009 at 12:49 PM, Gopinath R gopiindia...@gmail.comwrote: I am a newbie to python. i like to learn python strongly. which version is recommended to start with 2.6 or 3.0. I believe 3.0 has lot more features added, there is no backward compatibility in that. we cannot use some of the 2.6 syntaxes in that. for Example: raw_input. it worries me a lot. pls give some suggestion. I think one of the important features of python is the availability of a huge set of external libraries that make your programming easier (because you can reuse stuff, and not reinvent the wheel). This is true of python 2.6, but not yet true of python 3.x. So, assuming that you would like to make something useful with python (as opposed to toy programs), go with 2.6. I can't think of a strong reason for Sorry. This should have been I can't think of a strong reason for learning 3.x at this point of time ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Python at Schools
On Thu, Oct 1, 2009 at 2:17 AM, shameek ghosh shamee...@gmail.com wrote: college.So I retracked and instead started with teaching them effective ways of playing battleships using common search methods in algorithms etc Wow, this is a really cool insight, and an interesting way to motivate them. I'd love to hear more such ideas on how kids of this age can be motivated to take an interest in programming. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Implementing a fast factorial function in python
print f(1) This is a HUGE number. I don't think you are expected to get the answer by direct calculation. I would guess that you are expected to use mathematical reasoning to figure out the answer (and not computation) ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Performance benefits of Generators?
OTOH, Decorators , lambdas ('syntactic sugars') et al reduce the number of lines of code, depending on the scenario, for a given piece of complex logic, but these are 'slow'. But, I dont think the factor is huge enough to cause a performance bottleneck. I had similar reservations on list comprehensions, but in some cases the bytecode generated by LC is same as the one generated by the if-else/loop counterparts. If you are building apps wherein every microsecond matters, then it is better to time both variants - the sugars and their vanilla equivalents - and then choose the best. I'm wondering: if you are building apps wherein every microsecond matters, why are you doing it in Python? Python is bound to be about 10x slower than Java/C/C++ so for apps where performance is so important, you're better off writing in those languages. Or, better still, just replace the important parts with native C code. Python code should focus on what python is good at - readability, conciseness, maintainability. Leave the performance aspects to languages that are better at it. (Reference for the 10x slower comment - http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/ - Dhananjay is also on this list, so maybe he will also jump in with a response) navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Performance benefits of Generators?
No not yet. I am not building a application where every mu-sec matters. I appreciate the link and comments though. Will be helpful some day in the future. I guess my point is this: If you've chosen python as a language for your app, you have pretty much accepted that your application is not CPU bound. Hence you should not be worrying about the extra CPU cycles taken by advanced languages features. Use all possible language features (focusing on readibility and maintainability and other such things). Don't worry about the CPU performance unless there is a need to worry about, and even then, you should be thinking in terms of replacing a key function with C code rather than replacing a generator with a for loop. navin. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers