Longest string challenge: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.)
Line 1,677: Line 1,677:
<lang python>import fileinput
<lang python>import fileinput


# This returns True if the second string has a value on the
# originally, return len(a) - len(b) if positive, 0 otherwise.
# same index as the last index of the first string. It runs
# Observing that longer is used for its Boolean result,
# faster than trimming the strings because it runs len once
# and that '' is False, while any other string is True,
# and is a single index lookup versus slicing both strings
# longer need only to return a after removing len(b) characters,
# one character at a time.
# which is done without resorting to len().
def longer(a, b):
def longer(a, b):
while a and b:
try:
a, b = a[1:], b[1:]
b[len(a)-1]
return a
return False
except:
return True


longest, lines = '', ''
longest, lines = '', ''