Posts
 
Reputation
Joined
Last Seen
Ranked #905
Strength to Increase Rep
+5
Strength to Decrease Rep
-1
100% Quality Score
Upvotes Received
5
Posts with Upvotes
4
Upvoting Members
4
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
4 Commented Posts
0 Endorsements
Ranked #718
~10.2K People Reached
Favorite Forums
Member Avatar for knan

The method of Gribouillis uses a lot of sorted(). They generate new lists. A sort "in place" might be faster and you only need one sort() call [CODE] L = [ (k,x) for k, v in dict1.items() for x in v] L.sort() [/CODE] Tuples are sorted by element.

Member Avatar for grantjenks
0
807
Member Avatar for Banjoplucker

Maybe this might give you a clue. [ICODE]doc_wp = open('path', 'wb')[/ICODE] Opens a file with name: path [CODE=python] while out_block: listing = os.listdir(root) out_block = f.read(int(carved)) for each_file in listing: doc_wp = open(os.path.join(root,each_file), 'ab') doc_wp.write(out_block) doc_wp.close() [/CODE]

Member Avatar for djidjadji
0
107
Member Avatar for yond

why don't you use the re module [CODE=python] import re def countSubStringMatchRecursive(target,key): return len(re.findall(key,target)) [/CODE]

Member Avatar for TrustyTony
0
100
Member Avatar for novice20

It can all be done in one call to re.findall() or re.finditer() [CODE] mynums = [int(x) for x in re.findall('\d+(?=:)',dd)] [/CODE]

Member Avatar for novice20
0
107
Member Avatar for rotexhawk

The fastest way to make a 2D array of a constant value is [CODE=python] array2D= [[0]*numCols]*numRows [/CODE]

Member Avatar for djidjadji
0
209
Member Avatar for hughesadam_87

The solution of tonyjv can be written in a single line. Only sort on one index here. [CODE=python] korvatunturi = { 'Father Christmas': [[130, 123,12], [12,223,122]], 'Rudolf' : [[12,3,23], [235,24,3]] } dummy = [v.sort(key = lambda x: x[index]) for v in korvatunturi.values()] [/CODE] Because the lists are sorted in place …

Member Avatar for djidjadji
0
372
Member Avatar for tillaart36

To be able to see the improvement of an optimization timing the code is a good instrument. If I time your original code with your example images using the following [code=python] import datetime t1=datetime.datetime.now() matchTemplate(searchImage, templateImage) delta=datetime.datetime.now()-t1 print "Time=%d.%d"%(delta.seconds,delta.microseconds) [/code] I get [icode]Time=4.625000[/icode] If we look at the code we …

Member Avatar for vegaseat
2
3K
Member Avatar for kadvar

Because the keyword is not always ending with an '&' character a slight adjustment [code=python]>>> patt = r'keywords=([^&]+)' >>> re.findall(patt, "keywords=james&keywords=john&keywords=brian") ['james', 'john', 'brian'][/code]

Member Avatar for woooee
0
87
Member Avatar for AutoPython

What kind of steps are you talking about. Do the steps only apply to the current character? If yes, you just made a substitution encryption and that is easy to crack. Just count the character frequencys and compare with known counts for certain languages. If you use the previous characters …

Member Avatar for ov3rcl0ck
0
560
Member Avatar for SuperMetroid

re.search() returns a MatchObejct, not the string that matches the regex. Look up in the docs what you can do with it to get the match string. A better regex to use is [CODE=python] matchObj = re.search('(?<=http://user.url.com/)[^"]+', pg_r) if matchObj: pass # found a match [/CODE]

Member Avatar for Ene Uran
0
135
Member Avatar for akie2741

It made with Microsoft Word. The WORST HTML editor there is. A good cadidate to use is module: HTMLParser First clean up the file and get rid of all the style stuff and comments. Then you have a better view of what the file is made up of.

Member Avatar for djidjadji
0
94
Member Avatar for leegeorg07

[CODE=python] for i in range(1, 638): try: temp=start+str(i) permlist.append(str(url.urlopen(temp).readlines()[88])) textlist.append(str(url.urlopen(temp).readlines()[77])) except Error: # catch any exception and continue the for loop print "Error at index %d."%i [/CODE]

Member Avatar for ov3rcl0ck
0
204
Member Avatar for alex-VX

On MS-Windows there is a system window message that you can process to indicate that you don't want the screensaver to become active. You can use it to monitor when the screensaver gets active. You must be in a GUI program, from a commandline python program it does not work. …

Member Avatar for alex-VX
0
104
Member Avatar for awa

The following code is a bit cleaner [code=python] import re infileName = raw_input("filename ") infile = open(infileName, 'r') data = infile.readlines() printLines = False skipCount = 0 for index, line in enumerate(data): if "KEY1:" in line: printLines = True skipCount = 4 continue if "---" in line: printLines = False …

Member Avatar for awa
0
277
Member Avatar for mahela007

[QUOTE=mahela007;991473]Is it good programming practice to refer to class variables by using their instances? like mycow.numcows?[/QUOTE] There are times that referring by self is the way to go. If you use [ICODE]self.somevar[/ICODE] python first looks if there is a member variable named [ICODE]somevar[/ICODE]. If not found: look for a class …

Member Avatar for djidjadji
0
172
Member Avatar for AutoPython

if the number in str format contains a '.' character use split() [code=python] numsplit = str(num).split('.') num_int = int(numsplit[0]) num_dec = numsplit[1] # this is a string [/code]

Member Avatar for AutoPython
0
190
Member Avatar for dbmikus

The reason is that you can't represent all numbers exact with floating point objects. You have to approximate the number because you have a limited number of bits. The str() function does some pretty printing of float numbers (that includes some rounding). If you print the exponential version you see …

Member Avatar for dbmikus
0
229
Member Avatar for lllllIllIlllI

It takes a long time because many fib-numbers are calculated a lot. If you store the numbers you already know it goes pretty fast. And these results are stored for the duration of the program so the next call to getFib(50) is instantaneous Use a class variable to store the …

Member Avatar for sneekula
0
207
Member Avatar for Caleb2419
Member Avatar for edward_pedro

Have a look for the "grep" tool that is available for your OS. Ignore case searching is done with the -i option

Member Avatar for vegaseat
0
148
Member Avatar for gianniszaf

If your called function for a customer takes 100%CPU load you will take longer to complete the whole task due to scheduling the tasks. If the function is an RPC you move the load to the server, only if it is a server farm or it has multi CPU you …

Member Avatar for woooee
0
237
Member Avatar for lllllIllIlllI

[QUOTE=Gribouillis;984981]You could use [icode](bool(example) and example in "hello there")[/icode]. This is true only if example is a non empty substring of "hello there".[/QUOTE] There is no need to convert the example string to bool before testing. All objects in Python have a True/False value. [code=python]if example and (example in "hello …

Member Avatar for sravan953
0
151
Member Avatar for bgk111

It would have been better if you gave an example of your input and required output. The summing of VAR1 and VAR2 is not clear. [code=python] from itertools import izip #row=[] #col=[] #var1=[] #var2=[] def getSum(data): if not isinstance(data,list): data=[data] return sum(data,0) result = [(r,c,getSum(v1),getSum(v2)) for r,c,v1,v2 in izip(row,col,var1,var2) if …

Member Avatar for bgk111
0
93
Member Avatar for mediachicken

You can use the Image.paste(imagesrc, box) method [URL="http://www.effbot.org/imagingbook/image.htm#tag-Image.Image.paste"]PIL-doc Image.Image.paste[/URL]

Member Avatar for Ene Uran
0
2K