Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Python
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Python section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old November 8th, 2007, 07:13 AM
Authorized User
Join Date: Mar 2005
Location: Zagreb, , Croatia.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Python code optimization

Need some hints in speeding up the Python scripts!!!

(1)Except partial objects module importing, i need to find out how to
improve performance in spatial and time consumption!
%instead of importing a whole gzip module
import gzip
%I use partial import of methods I am going to use, from the gzip module
import compress from gzip
import decompress from gzip

The example is rudimentary, but it explains the problem in hand. Because even the simplest gui aplication extracts 8MB of memory space, and that is absolutely to much...
Please, if any hints come across your mind, feel free to post your code...

Reply With Quote
  #2 (permalink)  
Old January 9th, 2009, 03:03 PM
Registered User
Join Date: Jan 2009
Posts: 8
Thanks: 1
Thanked 1 Time in 1 Post
Default The other way around

I'm not sure I understand the question, but I think it's a syntax error.
You are meant to do: from MODULE import something
for example: from gzip import compress
you can also use import gzip.compress

You say that you want to optimise your code by avoiding the import of redundant modules, that's great, I'm not sure how much optimisation you'll get (it depends on how much redundancies you had before) but it sure can't heart. if you want to do some more hardcore optimisation checkout psyco.sourceforge.net
Reply With Quote
  #3 (permalink)  
Old December 13th, 2011, 04:13 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts


I solved the problem using this (horribly inefficient method):

def createList(word, wordList):
#Made a set, because for some reason permutations was returning duplicates.
#Returns all permutations if they're in the wordList

return set([''.join(item) for item in itertools.permutations(word) if ''.join(item) in wordList])

def main():

a = open('C:\\Python32\\megalist.txt', 'r+')
wordList = [line.strip() for line in a]
maximum = 0
length = 0
maxwords = ""

for words in wordList:
permList = createList(words, wordList)
length = len(permList)
if length > maximum:
maximum = length
maxwords = permList
print (maximum, maxwords)
It took something like 10 minutes to find the five-letter word that has the most dictionary-valid anagrams. I want to run this on words without a letter constraint, but it would take a ludicrous amount of time. Is there anyway to optimize this?
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why Python? elvisfeverr Python 5 June 4th, 2018 02:47 AM
python arafat.eajaz Other Programming Languages 0 July 18th, 2008 03:16 AM
RSS Code for python 2.5 (pyxml Vs 4Suite) dsampson BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 1 February 12th, 2008 09:49 AM

All times are GMT -4. The time now is 01:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.