Minor changes and fixes

__iter__ has to return an iter
This commit is contained in:
SimpleArt
2020-11-19 20:18:11 -05:00
parent 3412c05da2
commit 2c46e32782
2 changed files with 20 additions and 20 deletions

View File

@ -57,17 +57,17 @@ class Chromosome:
def __iter__(self): def __iter__(self):
"""Returns an iterable of the gene list""" """Returns an iterable of the gene list"""
return self.gene_list return iter(self.gene_list)
def __getitem__(self, k): def __getitem__(self, index):
"""Returns the k-th gene""" """Returns the indexed gene"""
return self.get_gene(k) return self.gene_list[index]
def __setitem__(self, k, gene): def __setitem__(self, index, gene):
"""Sets the k-th gene value""" """Sets the indexed gene value"""
self.set_gene(gene, k) self.gene_list[index] = gene
def __len__(self): def __len__(self):

View File

@ -21,18 +21,18 @@ class Population:
def remove_chromosome(self, index): def remove_chromosome(self, index):
"""Removes a chromosome from the indicated index from the population""" """Removes and returns a chromosome from the indicated index from the population"""
del self.chromosome_list[index] return self.chromosome_list.pop(index)
def remove_parent(self, index): def remove_parent(self, index):
"""Removes a parent from the indicated index from the mating pool""" """Removes and returns a parent from the indicated index from the mating pool"""
del self.mating_pool[index] return self.mating_pool.pop(index)
def remove_child(self, index): def remove_child(self, index):
"""Removes a child from the indicated index from the next population""" """Removes and returns a child from the indicated index from the next population"""
del self.next_population[index] return self.next_population.pop(index)
def reset_mating_pool(self): def reset_mating_pool(self):
@ -153,17 +153,17 @@ class Population:
def __iter__(self): def __iter__(self):
"""Returns an iterable of chromosomes""" """Returns an iterable of chromosomes"""
return self.chromosome_list return iter(self.chromosome_list)
def __getitem__(self, k): def __getitem__(self, index):
"""Returns the k-th chromosome""" """Returns the indexed chromosome"""
return self.get_chromosome(k) return self.chromosome_list[index]
def __setitem__(self, k, chromosome): def __setitem__(self, index, chromosome):
"""Sets the k-th chromosome""" """Sets the indexed chromosome"""
self.set_chromosome(chromosome, k) self.chromosome_list[index] = chromosome
def __len__(self): def __len__(self):