Consistent format for setting a slice of items
This commit is contained in:
@ -70,10 +70,14 @@ class Chromosome():
|
|||||||
chromosome[index] = gene
|
chromosome[index] = gene
|
||||||
to set the indexed gene.
|
to set the indexed gene.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Single gene
|
||||||
if isinstance(index, int):
|
if isinstance(index, int):
|
||||||
self.gene_list[index] = to_gene(gene)
|
self.gene_list[index] = to_gene(gene)
|
||||||
|
|
||||||
|
# Multiple genes
|
||||||
else:
|
else:
|
||||||
self.gene_list[index] = (to_gene(item) for item in gene)
|
self.gene_list[index] = [to_gene(item) for item in gene]
|
||||||
|
|
||||||
|
|
||||||
def __delitem__(self, index):
|
def __delitem__(self, index):
|
||||||
|
|||||||
@ -125,13 +125,11 @@ class Population:
|
|||||||
|
|
||||||
# Just one chromosome
|
# Just one chromosome
|
||||||
if isinstance(index, int):
|
if isinstance(index, int):
|
||||||
chromosome = to_chromosome(chromosome)
|
self.chromosome_list[index] = to_chromosome(chromosome)
|
||||||
|
|
||||||
# Multiple chromosomes
|
# Multiple chromosomes
|
||||||
else:
|
else:
|
||||||
chromosome = [to_chromosome(elem) for elem in chromosome]
|
self.chromosome_list[index] = [to_chromosome(item) for item in chromosome]
|
||||||
|
|
||||||
self.chromosome_list[index] = chromosome
|
|
||||||
|
|
||||||
|
|
||||||
def __delitem__(self, index):
|
def __delitem__(self, index):
|
||||||
|
|||||||
Reference in New Issue
Block a user