Python: TypeError: 'function' object has no attribute '__getitem__' -


i'm new python, , i'm having trouble code. i'm getting error

typeerror: 'function' object has no attribute '__getitem__' @ line 32 

i can't figure out what's going on. i've seen on internet, means using function list, can't figure out code. code

#! /usr/local/bin/python   import random   def genfirstgen():     print "first generation"     generation = []     chromosomecounter in range(0, 20):         chromosome = []         fitness = 0         genecounter in range(0, 10):             chromosome.append(random.randrange(0, 2))         genecounter in range(0, 10):             if (chromosome[genecounter] == 1):                 fitness += 1         chromosome.append(fitness)         generation.append(chromosome)         print gene     return generation   def findmostfit(generation):     failedset = [0,0,0,0,0,0,0,0,0,0,0]     highestfitness = 0     mostfit = 0     fitparents = []     gene = []     fitcounter in range(0, 10):         chromosomecounter in range(0, 20):             chromosome = [generation[chromosomecounter]] #  error here.             fitness  = chromosome[10]             highestfitness = 0             if (fitness > highestfitness):                 highestfitness = fitness                 mostfit = chromosomecounter          fitparents.append(generation[mostfit])         generation[mostfit] = failedset     return fitparents   def breedmostfit(parents):     mother = parents(random.randrange(0, 10))     father = parents(random.randrange(0, 10))     child = []     genecounter in range(0, 5):         parentgenetaken = random.randrange(0, 2)         if (parentgenetaken == 1):             child.append(mother[genecounter * 2])             child.append(mother[(genecounter * 2) + 1])         else:             child.append(father[genecounter * 2])             child.append(father[(genecounter * 2) + 1])     return child   def generation2():     newgeneration = []     gencounter in range(0, 20):         newgeneration.append(breedmostfit(findmostfit(genfirstgen)))     return newgeneration  def generationfunction(parentgen):     generation = []     gencounter in range(0, 20):         generation.append(breedmostfit(findmostfit(parentgen)))     return generation  generationfunction(generation2()) 

i'm @ wits end. can help? thanks!

on line 62 pass genfirstgen function findmostfit

newgeneration.append(breedmostfit(findmostfit(genfirstgen))) 

later on line 32 index it. guess wanted call function , pass results instead. replace line 62 with

newgeneration.append(breedmostfit(findmostfit(genfirstgen()))) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -