Live data from Hacker News

A Story to Explain Genetic Algorithms

jake.simvla.com

31–35 of 35 posts

Re: A Story to Explain Genetic Algorithms

#31
post #24
post #22

Earlier quoted context omitted.

Most of the code is a little verbose for Python. For example make() function could simply be: return [random.randint(1,10000) for x in range(4)] Also remember that a little kitten dies every time you write a for loop as follows: for index in range(len(some_list)):

I'm a python noob. Why does a kitten die? You're creating a new list of the same size of the source list (once) and iterating over it. How can you achieve the same w/out creating a new list?

Python god takes the kitten as a sacrifice for the unnecessary list of indexes you created :).

range(len(some_list)) is a convoluted way iterating over the elements of a list. What you are doing is creating a new list with elements [0,... lengh-1] and iterating over the elements of this list, only to immediately throw them away after using them as array index to grab the item you really want from the original list.

Instead you can just directly iterate over your original list: "for item in some_list". If you really need to know the index value, you can use enumerate: "for index, item in enumerate(some_list)"

One nice thing is that the "for x in y" lets you iterate over things (iterables) that you may be generating on the fly (e.g., all prime numbers smaller than N).

Re: A Story to Explain Genetic Algorithms

#32
post #16

Unrelated: this simvla network thing looks like a pale imitation of Svbtle.

@OP- Hey Jake, awesome article, really understand what Genetic Algorithms are now.

Also wanted to let the people that think Simvla is a ripoff of Svbtle know that I recently acquired Simvla from its creator and it's my first job to give Simvla a unique look. I respect Svbtle and I feel it's unfair to Dustin that Simvla copies the look he created.

Post reply on HN