Consistent format for setting a slice of items

This commit is contained in:
SimpleArt
2021-01-01 16:30:45 -05:00
parent 94793b1b05
commit 0386be436f
2 changed files with 7 additions and 5 deletions

View File

@ -70,10 +70,14 @@ class Chromosome():
chromosome[index] = gene
to set the indexed gene.
"""
# Single gene
if isinstance(index, int):
self.gene_list[index] = to_gene(gene)
# Multiple genes
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):

View File

@ -125,13 +125,11 @@ class Population:
# Just one chromosome
if isinstance(index, int):
chromosome = to_chromosome(chromosome)
self.chromosome_list[index] = to_chromosome(chromosome)
# Multiple chromosomes
else:
chromosome = [to_chromosome(elem) for elem in chromosome]
self.chromosome_list[index] = chromosome
self.chromosome_list[index] = [to_chromosome(item) for item in chromosome]
def __delitem__(self, index):