Posts
 
Reputation
Joined
Last Seen
Ranked #2K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
100% Quality Score
Upvotes Received
4
Posts with Upvotes
4
Upvoting Members
4
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
1 Commented Post
0 Endorsements
Ranked #1K
~45.9K People Reached

32 Posted Topics

Member Avatar for vegaseat

Try Rosetta Code for something10x faster [here](http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test#Python)

Member Avatar for paddy3118
1
2K
Member Avatar for vegaseat

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.

Member Avatar for Gribouillis
0
20K
Member Avatar for vegaseat

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.

Member Avatar for paddy3118
2
4K
Member Avatar for TrustyTony

... 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 …

Member Avatar for paddy3118
1
289
Member Avatar for vegaseat

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, …

Member Avatar for TrustyTony
5
6K
Member Avatar for vegaseat

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.

Member Avatar for sneekula
2
5K
Member Avatar for jobs

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.

Member Avatar for timogoosen
0
3K
Member Avatar for ultimatebuster

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.

Member Avatar for ultimatebuster
0
566
Member Avatar for TomD22

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 …

Member Avatar for SgtMe
0
578
Member Avatar for nevets04

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.

Member Avatar for vegaseat
0
214
Member Avatar for lrh9

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 …

Member Avatar for paddy3118
0
362
Member Avatar for bdesc100

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.

Member Avatar for paddy3118
0
113
Member Avatar for daniwebnewbie

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 …

Member Avatar for paddy3118
0
261
Member Avatar for orangie

[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 …

Member Avatar for paddy3118
0
119
Member Avatar for red999

[CODE=python] for i in range(year): principal += principal * interest_rate [/CODE] - Have fun!

Member Avatar for paddy3118
0
187
Member Avatar for Rejinacm

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 …

Member Avatar for paddy3118
0
116
Member Avatar for adam291086

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.

Member Avatar for paddy3118
0
93
Member Avatar for Fuse

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.

Member Avatar for paddy3118
0
138
Member Avatar for webamateur

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.

Member Avatar for woooee
0
95
Member Avatar for dr_kac

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 …

Member Avatar for paddy3118
0
191
Member Avatar for happimani

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.

Member Avatar for paddy3118
0
142
Member Avatar for nsandestin
Member Avatar for freddypyther

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 …

Member Avatar for jwenting
0
152
Member Avatar for jliu66
Member Avatar for jliu66

[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 …

Member Avatar for Lardmeister
0
119
Member Avatar for jliu66
Member Avatar for jrcagle

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() …

Member Avatar for jrcagle
0
115
Member Avatar for mjsinpl
Member Avatar for paddy3118
0
79
Member Avatar for MrShoot

[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] …

Member Avatar for Ene Uran
0
161
Member Avatar for grahhh

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 …

Member Avatar for paddy3118
0
185
Member Avatar for StrikerX11

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 …

Member Avatar for jrcagle
0
111
Member Avatar for Gumster

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.

Member Avatar for paddy3118
0
110

The End.