MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / evaluate

Function evaluate

genetic_algorithm/basic_string.py:24–32  ·  view source on GitHub ↗

Evaluate how similar the item is with the target by just counting each char in the right position >>> evaluate("Helxo Worlx", "Hello World") ('Helxo Worlx', 9.0)

(item: str, main_target: str)

Source from the content-addressed store, hash-verified

22
23
24def evaluate(item: str, main_target: str) -> tuple[str, float]:
25 """
26 Evaluate how similar the item is with the target by just
27 counting each char in the right position
28 >>> evaluate("Helxo Worlx", "Hello World")
29 ('Helxo Worlx', 9.0)
30 """
31 score = len([g for position, g in enumerate(item) if g == main_target[position]])
32 return (item, float(score))
33
34
35def crossover(parent_1: str, parent_2: str) -> tuple[str, str]:

Callers 1

basicFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected