Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Optional arguments

Name: Anonymous 2011-07-27 6:13


def find(str, ch, start=0):
  index = start
  while index < len(str):
    if str[index] == ch:
      return index
    index = index + 1
  return -1


Add a fourth parameter, end, that specifies where to stop looking. The default value of end should be len(str).

Name: Anonymous 2011-07-27 6:38

>>2
Symta:

find Str Ch Start=0 End=0
 -> cut Start End Str | ([I++_ !Ch @_]->I) |> Start+It :: ~1


Python:

def find(str, ch, start=0, end=None):
  index = start
  if end is None:
    end = len(str)
  while index < len(str):
    if index > end:
      break
    if str[index] == ch:
      return index
    index = index + 1
  return -1

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List