Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Hughmoris
Apr 21, 2007
Let's go to the abyss!
Thanks for the help.

Could someone break down what exactly is going on with this code?
code:
sum(int(x) for x in str(1234567890))
I was also shown this way to do it as well:
code:
for c in str(a): sum += int(c)
I know both of them will give me the end result, but if someone asked to step through the code and how it works I wouldn't be able to. I guess thats what sucks about learning from a book and not a class, being unable to receive different explanations for the same solution.

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
sum - takes the sum of an iterable
int(x) for x in str(1234567890) - a generator expression, it iterates over '1234567890'(strings are iterable and yield each charecter), and yields the integer

hey mom its 420
May 12, 2007

sum is a function that takes anything you can iterate over and gives you the sum of all the elements. You can iterate over a list, a generator, a file or something completely different.

You could do this
code:
digit_generator = (int(x) for x in str(123456789))
sum(digit_generator)
When doing something in the form of F(x) for x in blah without the angled brackets, that creates a generator. A generator is much like a list, but instead of storing all those list elements in memory, it will calculate one element at a time and return them to you as you ask for them. Also you can do stuff like:
code:
>>> digit_generator = (int(x) for x in str(123456789))
>>> digit_generator
<generator object at 0x7ff2910c>
>>> digit_generator.next()
1
>>> digit_generator.next()
2
>>> digit_generator.next()
3
The second code you provided is much more traditional, if you will. You make a variable to hold the sum, go over all the elements and add the value of each one to the sum.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
code:
sum(int(x) for x in str(1234567890))
This is built around a "generator expression", which is a bit complicated. Let's do it with a list comprehension first. That version would be:

code:
sum([int(x) for x in str(1234567890)])
(Same but with added brackets.)

First, a definition: an "iterable" is anything you can iterate over (ie. if you can say "for x in y", y is an iterable). A list is the most obvious one, but strings are also iterable (iterating returns every character in the string), and so is a dict (iterating returns the keys).

"sum" is a regular function that takes an iterable and adds all the elements together. sum([1, 2, 3]) returns 6. sum("hello") gives an error - it iterates over the string fine, but internally it tries to call "h" + "e", which is invalid.

"str" is a function that turns something into a string, and "int" is a function that turns something into an integer. Pretty simple.

"[expression for variable in iterator]" is a "list comprehension", a syntax that creates lists. (If you know any math, you might recognize this as the "for all" syntax. Let's see if the forum handles unicode: expressionvariableset.)

That goes through the iterator and gets each element (assigning it to the variable - x is just the traditional variable name), calls the expression (which usually uses the variable) and adds the result to another list. For example, one of the simplest is [x for x in [1,2,3]], which just returns another copy of [1,2,3] - for each x in [1, 2, 3], it just returns x itself. You can make a list of 0's with the same length as another list with [0 for x in [1,2,3]] - for each x in [1, 2, 3], return a 0. Or you can double every element within a list with [2*x for x in [1,2,3] - for each x in [1, 2, 3], return two times x.

So, what we're doing:

code:
str(1234567890) -> "1234567890"
[x for x in str(1234567890)] -> [x for x in "1234567890"] -> ["1", "2", ..., "0"]
[int(x) for x in str(1234567890)] -> [int("1"), int("2"), ..., int("0")] -> [1, 2, ..., 0]
sum([int(x) for x in str(1234567890)]) -> sum([1, 2, ..., 0]) -> 1+2+3+4+5+6+7+8+9+0
Ok, now for generator expressions: a "generator" is another type of iterable. It's an object that holds a sequence, except that instead of storing the entire list in memory it knows how to calculate the next value. When you call a generator's next() function, it returns the next value in the sequence. (That means, unlike a list, a generator could return values forever.) If you pass a generator to something that expects an iterable, like the sum() function, a for loop, or a list comprehension, it will call next() behind the scenes.

A "generator expression" is just like a list comprehension, except you use ()'s instead of []'s.

A simple generator expression:

code:
>>> g = (x for x in [1,2,3])   # basically turns the list into a generator
>>> g.next()
1
>>> g.next()
2
>>> g.next()
3
>>> g.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
You can also do the reverse - get a list form a generator using a list comprehension:

code:
>>> g = (x*2 for x in [1,2,3])
>>> [x for x in g]
[2, 4, 6]
If you're passing a generator expression to a function, so it's already surrounded by parentheses, you don't need to double up.

So sum(int(x) for x in str(1234567890)) works just like the list comprehension, except it never turns "1234567890" into a list in memory: instead, every time sum asks for another number to add, it gets the next character from the string and turns it into integer right then. This uses less memory, which makes no difference at all in this case but could be incredibly important if you're using sequences with thousands of elements. It's a good idea to get into the habit of using generators instead of list comprehensions, just so when you misjudge the length of a list you don't get bitten.

Allie
Jan 17, 2004

Bonus posted:

Yeah it's good practice to maximize generator use and minimize lists. Of course it's cool to use lists for stuff you know will be small, but it doesn't cost you anything to use generators and generator expressions, but you will save on memory space when the data sets get big.

Generator expressions were only added in Python 2.4, so if you're developing for 2.3 or earlier you pretty much can't use them at all - they'll cause SyntaxErrors.

I guess if you're developing for such an old version of Python, you should probably already be aware of that, but Python 2.3 is unfortunately still pretty widely deployed.

No Safe Word
Feb 26, 2005

As a note, you can just use list() on a generator expression to get the list, no need to do the comprehension.

But one thing you have to remember about generators is that you basically can only iterate over them once and then they'll just return empty results (and/or raise StopIteration depending on how you use it). If you want to reuse the values to be iterated over a lot, then you should either continually reuse the same generator expression to create it or just store the results in a list if the size is sensible.

king_kilr
May 25, 2007

Milde posted:

sum("hello") gives an error - it iterates over the string fine, but internally it tries to call "h" + "e", which is invalid.

'h' + 'e' is perfectly valid, the problem is sum appears to do
code:
total = 0
for i in iterable
    total += i
return total
(the error it raises says that int can't be added to str), except for the fact that it is hyper optimized and written in C.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Yeah, but I was slurring over that. You can actually pass sum a "start" parameter, so in theory sum("hello", "") should return "hello", but actually it gives a different error:

code:
>>> sum(["h", "e", "l", "l", "o"], "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sum() can't sum strings [use ''.join(seq) instead]

Allie
Jan 17, 2004

king_kilr posted:

'h' + 'e' is perfectly valid, the problem is sum appears to do
code:
total = 0
for i in iterable
    total += i
return total
(the error it raises says that int can't be added to str), except for the fact that it is hyper optimized and written in C.

I guess you're right, but I meant in a mathematical sense it doesn't make sense to add two characters together*, I wasn't really thinking about the addition operator being used for concatenation. I guess if the function were more generic, you'd expect to get the same string back you passed in, but I think that error is more useful than it actually working, since you'd probably never want to call sum on a string.

* Yes, I know that characters can correspond to code points which you could add together if you wanted to.

tripwire
Nov 19, 2004

        ghost flow
Apologies for what must be a stupid question, but reading the documentation has only made me more confused about this.

Is there any way to make your own low level data structures in python? What I want is a data structure that is a table of 200 rows with 20 columns, and each value is base 4 (i.e. just 2 bits). Is there any compact fast way to do this?

Some background: my program will be receiving a stream of these tables and it has to add the current table to a set of unique tables, but only if the current table is "different' than each existing table in the set by a certain threshold amount. At this point, I want my compare function to return a float from 0.0 to 1.0 that corresponds to the amount of nonmatching values between the two tables, divided by the size of the table. Because this program will be running through thousands and thousands of tables, I really want a compact encoding that is lightweight enough that I can store about 20 000 unique tables and still compare the present table to every previous one without chewing up a huge amount of cputime and ram.

I know I can do this with a sequence of integers and just use values 0 through 3, but I'm worried about all the overhead getting in the way.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

tripwire posted:

Is there any way to make your own low level data structures in python? What I want is a data structure that is a table of 200 rows with 20 columns, and each value is base 4 (i.e. just 2 bits). Is there any compact fast way to do this?
Check out the array module. Makes space efficient arrays of numbers.
You have to give it an element size of at least one byte, but you could just do some bitwise operations to fit the 4 values if you need.

http://docs.python.org/lib/module-array.html

If you want finer control try the struct library which lets you pretty much manipulate c structs from python.

http://docs.python.org/lib/module-struct.html

Both are in the standard library distribution.

Destroyenator fucked around with this message at 10:47 on May 15, 2008

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

No Safe Word posted:

As a note, you can just use list() on a generator expression to get the list, no need to do the comprehension.

Yes, except list comprehensions are marginally faster than calling list on a generator expression. Also of note is that tuple([list comprehension]) is faster than tuple(generator expression). Building tuples from a list is faster than building tuples from a generator, though it uses more memory. Generally, generators will use less memory but may not always be faster when interacting with builtins.

Habnabit fucked around with this message at 13:48 on May 15, 2008

tripwire
Nov 19, 2004

        ghost flow

Destroyenator posted:

Check out the array module. Makes space efficient arrays of numbers.
You have to give it an element size of at least one byte, but you could just do some bitwise operations to fit the 4 values if you need.

http://docs.python.org/lib/module-array.html

If you want finer control try the struct library which lets you pretty much manipulate c structs from python.

http://docs.python.org/lib/module-struct.html

Both are in the standard library distribution.

Thanks, I feel stupid for not realizing that on my first look through the docs.

I decided to simply pickle a dictionary of integers for the time being just because I want to get this working first.

I'm having trouble visualizing how I'm going to implement this algorithm. I have to calculate the average distance to the k nearest neighbors of this object. If the average distance is above a threshold then I add the object, and if not I discard it. Has anyone done something similar in the past, just looping through every value in 2 dictionary's for every dictionary thats accumulated? It seems like I'm approaching it in an inefficient way.

tripwire fucked around with this message at 14:51 on May 15, 2008

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!
In python you can use a tuple as the key for a dictionary, so in your case the tuple could hold x,y offsets.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
Things to add to the op:

Implementations
tinypy - http://www.tinypy.org/ - Sexy small implementation that compiles to C
pypy - http://codespeak.net/pypy/dist/pypy/doc/home.html - Almost self-hosting python implementation? Not sure.


Links:
Norvig's Infrequently asked questions - http://norvig.com/python-iaq.html - This man exemplifies elegant code. His solutions are just... beautiful.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

deimos posted:

Things to add to the op:

Implementations
tinypy - http://www.tinypy.org/ - Sexy small implementation that compiles to C
pypy - http://codespeak.net/pypy/dist/pypy/doc/home.html - Almost self-hosting python implementation? Not sure.


Links:
Norvig's Infrequently asked questions - http://norvig.com/python-iaq.html - This man exemplifies elegant code. His solutions are just... beautiful.

Added

fritz
Jul 26, 2003

Do any of you guys know anything about the new string formatting stuff in python 3000? In particular, I understand that the "%" formatting operator is going away, but will we be obliged to use the fancy new syntax with positional and named fields?

hey mom its 420
May 12, 2007

As far as I understand it, % is not going away, but there will be a sort of templating mini language available for more advanced stuff. Although from my usage, I've never caught myself saying "Gee golly, I wish there was something more advanced than the % operator built right into Python!" because it, along with regexes, has suited all my string manipulating needs so far.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Bonus posted:

As far as I understand it, % is not going away, but there will be a sort of templating mini language available for more advanced stuff. Although from my usage, I've never caught myself saying "Gee golly, I wish there was something more advanced than the % operator built right into Python!" because it, along with regexes, has suited all my string manipulating needs so far.

Well, it's not a huge deal, but I have often wished to be able to write

code:
print "%(i + 1)d" % locals()
instead of

code:
j = i + 1
print "%(j)d" % locals()
I could just use the positional syntax, but I prefer the other on principle.

bitprophet
Jul 22, 2004
Taco Defender
Why those two instead of e.g.
code:
print "%d" % i
or
code:
print "%d % (i+1)
? Granted that %(dictkey)d is useful in more complex scenarios, but given your actual example, using that format and locals() (which seems kinda unPythonic to me, much less explicit than making an anonymous dict after the % operator) seems like overkill.

EDIT: I guess this is what you meant by 'positional' (I just tend to think of it as "normal" :downs:), but that still doesn't quite answer the question of what's wrong with performing the +1 expression on the right hand side of the %.

bitprophet fucked around with this message at 17:50 on May 21, 2008

Allie
Jan 17, 2004

JoeNotCharles posted:

Well, it's not a huge deal, but I have often wished to be able to write

That first example would be the equivalent of int(locals()['i + 1']), which doesn't make any sense to me. What exactly are you trying to point out?

I think you might be expecting a little too much out of string formatting operations. They're just for formatting, after all.

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

deimos posted:

pypy - http://codespeak.net/pypy/dist/pypy/doc/home.html - Almost self-hosting python implementation? Not sure.

Can someone explain what pypy is and how it all fits together? I have looked at the website and I don't quite understand it, you have python written in python, then RPython, then something which hopefully will one day be faster than C. How does it work?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Milde posted:

That first example would be the equivalent of int(locals()['i + 1']), which doesn't make any sense to me. What exactly are you trying to point out?

That it would be nice to be able to embed expressions in strings, instead of just variable names.

quote:

I think you might be expecting a little too much out of string formatting operations. They're just for formatting, after all.

Yes, that's the problem.

Benji the Blade
Jun 22, 2004
Plate of shrimp.

Mashi posted:

Can someone explain what pypy is and how it all fits together? I have looked at the website and I don't quite understand it, you have python written in python, then RPython, then something which hopefully will one day be faster than C. How does it work?

I am by NO means a PyPy expert, though I do think it's pretty cool.

The developers say PyPy is a tool for generating virtual machines. PyPy started as a Python interpreter written in Python, and it can still be used as such on top of CPython and you get an ungody slow Python interpreter. And so, they decided to write a translation layer that takes RPython (a subset of Python) and translates it into C code. They then wrote the interpreter in RPython and now the interpreter can be translated into C code, and is currently around twice as slow as CPython.

However, they can use a different translator to automatically translate PyPy onto different platforms such as CLI/.NET, JVM, and apparently also less obviously useful platforms such as Smalltalk and Scheme.

Of course, the translator will translate anything from RPython to C/CLI/JVM or whatever, so people can write whatever interpreters or other programs they like in RPython (though using RPython in production isn't really advised right now, from what I can tell). You can also use RPython to generate libraries for CPython that have been translated into C and compiled.

Anyway, they're working on things like JIT compilation/optimization and messing around with writing plugins for PyPy to change the behavior of the language in various ways (like reimplementing Stackless).

Really, the interesting thing to me is that if PyPy really takes off, it promises to make Jython and IronPython and CPython obsolete, since it could be run on pretty much any platform. I'd also like to see a stable RPython that would be useful for application developers to write high performance Python. Of course, if they get the JIT compiler in order, you should pretty much get the same speed boost out of any piece of your code that conforms to the constraints of RPython, even if it's embedded in the middle of your Python program. Sadly, I keep reading that the JIT is currently pretty seriously broken, so who knows if it'll ever pan out.

If you're interested in the gritty details of it all, this Google Tech Talk goes into some depth on it. The sound gets better after a little while, but it's still kinda a lacking presentation.

No Safe Word
Feb 26, 2005

JoeNotCharles posted:

Yes, that's the problem.
String formatting operations only doing formatting is ... a problem? :confused:

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

No Safe Word posted:

String formatting operations only doing formatting is ... a problem? :confused:

Did you read the post I was replying to?

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

Benji the Blade posted:

I am by NO means a PyPy expert, though I do think it's pretty cool.

The developers say PyPy is a tool for generating virtual machines. PyPy started as a Python interpreter written in Python, and it can still be used as such on top of CPython and you get an ungody slow Python interpreter. And so, they decided to write a translation layer that takes RPython (a subset of Python) and translates it into C code. They then wrote the interpreter in RPython and now the interpreter can be translated into C code, and is currently around twice as slow as CPython.

However, they can use a different translator to automatically translate PyPy onto different platforms such as CLI/.NET, JVM, and apparently also less obviously useful platforms such as Smalltalk and Scheme.

Of course, the translator will translate anything from RPython to C/CLI/JVM or whatever, so people can write whatever interpreters or other programs they like in RPython (though using RPython in production isn't really advised right now, from what I can tell). You can also use RPython to generate libraries for CPython that have been translated into C and compiled.

Anyway, they're working on things like JIT compilation/optimization and messing around with writing plugins for PyPy to change the behavior of the language in various ways (like reimplementing Stackless).

Really, the interesting thing to me is that if PyPy really takes off, it promises to make Jython and IronPython and CPython obsolete, since it could be run on pretty much any platform. I'd also like to see a stable RPython that would be useful for application developers to write high performance Python. Of course, if they get the JIT compiler in order, you should pretty much get the same speed boost out of any piece of your code that conforms to the constraints of RPython, even if it's embedded in the middle of your Python program. Sadly, I keep reading that the JIT is currently pretty seriously broken, so who knows if it'll ever pan out.

If you're interested in the gritty details of it all, this Google Tech Talk goes into some depth on it. The sound gets better after a little while, but it's still kinda a lacking presentation.

Thanks for taking the time to type that out, makes alot more sense now. :)

king_kilr
May 25, 2007
If/when the PyCon talks are released(they were all recorded), the PyPy one was really excellent.

king_kilr
May 25, 2007
EDIT: I hate my life.

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!
Ok, indulge me.. I'm playing around implementing something I use in PHP to make my life easier and scare my co-workers:

code:
def dictref(d,keys):
	if (len(keys)):
		return dictref(d[keys.pop(0)],keys)
	return d

di = {'a':{'b':{'c':{'d':1}}}}
keys = ['a','b']

print str(dictref(di,keys))

# outputs:
{'c': {'d': 1}}
Basically it is a way to traverse a multidimensional dictionary using a list of keys. A backwards version of this (creating a multidimensional dict from a flat one) can be useful if you are iterating SQL results and you want the data organised in a certain way.

For fun, can anyone implement the dictref function in an elegant one liner?

hey mom its 420
May 12, 2007

Well you seem to have it solved quite nicely, maybe you could rewrite it like this
code:
def dictref(d, keys):
  return dictref(d[keys.pop(0)],keys) if keys else d
You could make it a complete one liner using a lambda, but it's generally not a good idea to use recursion with lambdas because it uses the local scope of its definition instead of its own scope for recursing. So stuff like this can happen.
code:
>>> take = lambda lst, n: lst[:1] + take(lst[1:],n-1) if n else []
>>> take([1,2,3,4],2)
[1, 2]
>>> fake_take = take
>>> del take
>>> fake_take([1,2,3,4],2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <lambda>
NameError: global name 'take' is not defined

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!
I see what you mean about lambda's not having their own scope, but doesn't the error in your example occur if you copy / del a regular function?

Also I suppose it would be impossible to use recursion in an anonymous lambda without examining the stack or something like that.

hey mom its 420
May 12, 2007

Whoops, my bad! It seems that deleting normal functions also exhibits this behavior. I don't know why, but I thought that inside a function, the function name overshadowed the function name in the parent namespace or was set if it wasn't present. Most interesting indeed. Anyone have any ideas on how to get around this problem in normal functions? Something like
code:
arguments.callee
that javascript has, maybe.

So anyway yeah, you could make this a lambda then, like so
code:
dictref = lambda d, keys: dictref(d[keys.pop(0)], keys) if keys else d

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

Bonus posted:

Whoops, my bad! It seems that deleting normal functions also exhibits this behavior. I don't know why, but I thought that inside a function, the function name overshadowed the function name in the parent namespace or was set if it wasn't present. Most interesting indeed. Anyone have any ideas on how to get around this problem in normal functions? Something like
code:
arguments.callee
that javascript has, maybe.

I looked this up earlier. I was both impressed at python's flexibility and a little dissapointed that there wasn't a magic variable to reference the current function:

code:
import inspect
def myname():
    return inspect.stack()[0][3]
http://telin.ugent.be/~slippens/drupal/node/148

Scaevolus
Apr 16, 2007

Python Tips, Tricks, and Hacks This is a nice article to remind you of a few things that Python does elegantly that you might forget.

For example:

Mashi posted:

code:
def dictref(d,keys):
	if (len(keys)):
		return dictref(d[keys.pop(0)],keys)
	return d

if (len(keys)) == if keys

The empty dictionary, string, and list all evaluate to false, so checking the length explicitly is unnecessary.

Bonus used this in his ternary one liner (I'm not yet sure how I feel about the [expr] if [cond] else [expr] syntax).

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.

Scaevolus posted:

(I'm not yet sure how I feel about the [expr] if [cond] else [expr] syntax).

I prefer it because it's easier and more natural to read, which is one of the major reasons I prefer to python.

DTMTCM
Feb 18, 2005
I misclicked post icon so I have this account now.
Here's a quick question. I'm trying to create a gui in python that has a tree view widget (see JTree which is part of Java's swing library). The only experience I have with python and guis are just some quick ones that I've made using basic Tkinter widgets. Does Tkinter have a tree view similar to what I'm asking for or should I used another module? Also, do you guys have any good python gui books or resources you can recommend?

ynef
Jun 12, 2002

urmomlolzinbed posted:

Here's a quick question. I'm trying to create a gui in python that has a tree view widget (see JTree which is part of Java's swing library). The only experience I have with python and guis are just some quick ones that I've made using basic Tkinter widgets. Does Tkinter have a tree view similar to what I'm asking for or should I used another module? Also, do you guys have any good python gui books or resources you can recommend?

My recommendation, due to me not knowing Tkinter at all, is to simply use Glade to build a GUI (if this is in a Linux environment, you didn't say). Glade spits out an XML file, and like two lines of Python reads that XML file and gives you your GUI. All events that you want to handle are set in the XML file, so you just need to write Python functions for dealing with them.

tripwire
Nov 19, 2004

        ghost flow
This isn't strictly a python question, but its related so I figured I'd ask here. I've been tweaking and fiddling with a genetic algorithm in python for a while, and Ive had some success using parallel python to break up the population that needs to be evaluated so it each required evaluation can be farmed out to an available processor.

This works fine because each member of the population that needs evaluating shouldn't have any effect on the evaluations for other members; their evaluation is objective, and generally is in the form of a positive float.

I've been scratching my head on how I can adapt this new variation on the algorithm:
Instead of receiving an objective score, the first individual is characterized by its behavior during evaluation (in this case, just an x,y coordinate pair), and that behavior is added to an archive of behaviours for the run. Each future evaluation is compared to the nearest 15 neighbors in the archive or within the current population and only added if it is higher than some dynamically set threshold.

IS it impossible to do this in parallel?

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

tripwire posted:

This isn't strictly a python question, but its related so I figured I'd ask here. I've been tweaking and fiddling with a genetic algorithm in python for a while, and Ive had some success using parallel python to break up the population that needs to be evaluated so it each required evaluation can be farmed out to an available processor.

I thought the Global Interpreter Lock made this form of threading pointless? Or are you doing multiple processes?

  • Locked thread