diff --git a/src/structure/chromosome.py b/src/structure/chromosome.py index 458ed6b..fa0be12 100644 --- a/src/structure/chromosome.py +++ b/src/structure/chromosome.py @@ -55,20 +55,10 @@ class Chromosome: def __repr__(self): - """Format the repr() output for the chromosome""" - output_str = '' - for gene in self.gene_list: - output_str += gene.__repr__() + """Create a backend string of the chromosome. Ex '1, 2, 3'.""" + return ', '.join(repr(gene) for gene in self.gene_list) - return output_str def __str__(self): - """Create a string of the chromosome. Ex chromsome = 1,2,3""" - output_str = '' - for gene in self.gene_list: - if gene == self.gene_list[0]: - output_str += str(gene.get_value()) - else: - output_str += ',' + str(gene.get_value()) - - return output_str + """Create a printable string of the chromosome. Ex '[1][2][3]'.""" + return ''.join(str(gene) for gene in self.gene_list) diff --git a/src/structure/gene.py b/src/structure/gene.py index bc8f054..ae0bcea 100644 --- a/src/structure/gene.py +++ b/src/structure/gene.py @@ -29,5 +29,10 @@ class Gene: def __repr__(self): - """Format the repr() output value""" - return f'[{self.value}]' + """Create a backend string of the chromosome. Ex '1'.""" + return str(self.value) + + + def __str__(self): + """Create a printable string of the chromosome. Ex '[1]'.""" + return f'[{str(self.value)}]' diff --git a/src/structure/population.py b/src/structure/population.py index 6445d05..ccd52df 100644 --- a/src/structure/population.py +++ b/src/structure/population.py @@ -148,11 +148,11 @@ class Population: """Sets the fitness value of the population""" self.fitness = fitness - +''' def __repr__(self): - """Returns a string representation of the entire population""" + """Returns a backend string representation of the entire population""" pass - +''' def print_all(self): """Prints information about the population in the following format: