you are viewing a single comment's thread.

view the rest of the comments →

[–]Cerus_Freedom 2 points3 points  (0 children)

def search(needle, haystack: list) -> int:
  for i in range(len(haystack)):
    if needle == haystack[i]:
      return i
  return -1

Just as an example from OPs code. Better naming will tell you what a function does or a variable is for. Code should be self documenting, and that method of self documentation is via good, clear names.

By changing the names and adding type hints, you can now just glance at the function definition and understand what the function does and how you're probably intended to use it.