- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 4
- Posts with Upvotes
- 4
- Upvoting Members
- 4
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
32 Posted Topics
Re: Try Rosetta Code for something10x faster [here](http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test#Python) | |
Re: Both the original and vegaseat code needs to replace longer words first to get over the problem where a shorter word is part of a longer one. | |
Re: Neat. Personally I would try: duplicate_word_list = [word for word, count in Counter(word_list).most_common() if count > 1] Just because I am used to using most_common with Counter. | |
Re: ... The argument about n++ and n-- is that there is also --n and ++n and that C allows assigning as well as auto increment/decrement in one statement, which is both error prone and hard to maintain. Overall, I'm happy with the decision to leave it out of Python. writing … | |
Re: It is good to know both methods of representing a 2D array - list of lists and dictionary mapping index pairs to values. In this particular case though, you can transpose a list using zip(*matrix) to give these results: >>> matrix34 = [ [2.5, 3.0, 4.0, 1.5], [1.5, 4.0, 2.0, … | |
Re: If you want even larger numbers from a simple series then the [Ackermann function](http://rosettacode.org/wiki/Ackermann_function#Python) is to factorials as factorials are to a simple count of integers. | |
Re: If you are returning longs you can selectively turn them into integers using int() e.g: [CODE]>>> a = ((11L,), (12L,), (13L,), (14L,), (15L,), (166666666666L,)) >>> b = tuple((int(i[0]),) for i in a) >>> b ((11,), (12,), (13,), (14,), (15,), (166666666666L,)) >>> [/CODE] - Paddy. | |
Re: The Pythonic way is to [B]not[/B] litter Python code with type checks, but to proceed as if the names refer to data of the correct type. To aid in this, Python strives to be readable, and your functionality/coverage tests should be comprehensive. | |
Re: Take an offensive term: [INDENT] You are being stupid[/INDENT] Water it down: [INDENT] You are being [I]slightly [/I]stupid[/INDENT] Water it down some more with a smiley: [INDENT] You are being slightly stupid :D[/INDENT] And more: [INDENT] [I]No offence[/I], but you are being slightly stupid :D[/INDENT] It just seems to be … | |
Re: Even competent programmers will never know all of C++. The bit of C++ you need to be proficient in is the C language. You might point out that "if Python is good enough for MIT ..." :-) - Paddy. | |
Re: If data is truly coming from an untrusted source, then validate it to death as soon as the dataappears in your program, but don't sprinkle checks thoughout your source. Assume fellow programmers know what they are doing - don't add 'defensive code' to check arguments for example - assume that … | |
![]() | Re: The cure seems worse than the disease. have you actually tried returning a tuple of all results and the caller just picking the ones it needs? - Paddy. |
Re: Use whatever is easiest to write the code in. Get it right. Profile; then see if you need to worry about optimisation. Once you have a working program, you often find that optimisations are unnecessary, or, when you profile, you find that the bottleneck isn't where you thought it might … | |
Re: [QUOTE=orangie;805391]I would really appreciate a help to this problem: Let's say x = Class() x.name = 'the_name' x.value = 10 if you were only give the 'the_name' how do you get the instance ref, x to get x.value[/QUOTE] You might try keeping a class variable that maps all names to … | |
Re: [CODE=python] for i in range(year): principal += principal * interest_rate [/CODE] - Have fun! | |
Re: Listen to the guy who told you to use a list. If you don't know about exec, your probably going about solving your problem in the wrong way by using it. Try thinking of how you might solve things using a list or a dictionary. exec is something to use … | |
Re: You seem to be wanting to store a [I]collection [/I]of information. Have a look at lists, sets and dictionaries in the python documentation. - Paddy. | |
Re: Try re.finditer as in: [CODE=python] def patternMatching(pattern, string): print '\n'.join(string[matchobj.start():matchobj.end()] for matchobj in re.finditer(pattern, string)) [/CODE] - Paddy. | |
Re: Hi, I am not sure how you access the P_LastName field in a member of q. If it is something like q[0].P_LastName then use the key argument to sort like this: q.sort(key = lambda x: x.P_LastName) - Paddy. | |
Re: Here is a Python 2.5 version that uses groupby and generator comprehensions. I guess its not much use if you haven't got to them in your Python studies as yet but here goes: [CODE=PYTHON] >>> from StringIO import StringIO >>> from itertools import groupby >>> # Dummy file >>> instring … | |
Re: Try [URL="http://www.python.org/doc/2.4.3/whatsnew/whatsnew24.html"]here[/URL]. As someone pointed out, we are now at [URL="http://docs.python.org/whatsnew/whatsnew25.html"]2.5[/URL] - Paddy. | |
Re: what functions in other languages did you use? | |
Re: When given a codebase to understand, automatically generated overviews such as UML diagrams and maybe Doxygen views might help and seldom hinder. When given a task and a clean slate, then you have to be somewhat aware of when to put down the charts and start writing code. As for … | |
Re: What have you got so far? How do you have the data represented? | |
Re: [QUOTE=jliu66;454032]Thanks a lot. But this is kind of risky for a large project as you may have many loop and if to have indentations. John[/QUOTE] Not really. For your large project you factor and re-factor the code, to improve maintainability which also improves readability. People have add-hoc rules like "a … | |
Re: This might help: [url]http://effbot.org/librarybook/csv.htm[/url] | |
Re: One of the reasons for encompassing most of your code in a function, it does not have to be main, but many choose to use main, is that it allows you to use this idiom of having your program also act as a module: [code] if __name__ == '__main__': main() … | |
Re: Try [url]http://wiki.python.org/moin/BeginnersGuide[/url] - Paddy. | |
Re: [QUOTE=StrikerX11;446731][code] >>> LIST = ["CANADA", "HELLO", "I TOLD YOU SO"] >>> conv_list=[] >>> for el in LIST: conv_list +=[el.lower()] >>> conv_list ['canada', 'hello', 'i told you so'] [/code][/QUOTE] You might also try: [code] list_in = ["CANADA", "HELLO", "I TOLD YOU SO"] list_out = [] for element in list_in: list_out.append(element.lower()] [/code] … | |
Re: Instead of: [code=python] my_list = [eval(n) for n in my_line.split(None)] [/code] of answer #3 of vegaseat, it is always better to reduce use of eval to an absolute minimum, so if you know it's a file of floats then use float() like this: [code=python] my_list = [float(n) for n in … | |
Re: Strings are known as immutable. You cannot take a string object and change its value without creating another string, so although you can have two names refer to the same string object, when you create a new string object and assign it to one of the names, the other name … | |
Re: If you install wxpython and run the demo there are examples of grid displays given. As other posters have said, use the CSV module to work with CSV as it is very flexible as well as being easy to use. - Paddy. |
The End.