From a071c64242c01e6cfd212960796556945bd225d5 Mon Sep 17 00:00:00 2001 From: Bernardo Sulzbach Date: Mon, 7 Jul 2014 19:56:54 -0300 Subject: [PATCH] Another commit --- .../arrays_and_strings/reverse_str.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/further_examples/arrays_and_strings/reverse_str.py b/src/further_examples/arrays_and_strings/reverse_str.py index 4d7543f..83c70d0 100644 --- a/src/further_examples/arrays_and_strings/reverse_str.py +++ b/src/further_examples/arrays_and_strings/reverse_str.py @@ -1,4 +1,31 @@ #!/usr/bin/python3 +<<<<<<< HEAD +======= +# mari von steinkirch @2013 +# steinkirch at gmail + + +def reverse_str(s): + ''' in place ''' + sr_ls = [] + for i in range(len(s)-1, -1, -1): + sr_ls.append(s[i]) + return ''.join(sr_ls) + + + + +def main(): + s1 = 'abcdefg' + s2 = 'buffy' + s3 = '' + print(reverse_str(s1)) + print(reverse_str(s2)) + print(reverse_str(s3)) + +if __name__ == '__main__': + main() +>>>>>>> parent of 7b79f58... Faster, better, stronger # Mari von Steinkirch @ 2013 # mari.wahl9@gmail.com @@ -60,4 +87,4 @@ for function in (reverse_1, reverse_2, reverse_3, reverse_lambda): # We print the function's name and its benchmark result. print("{:<30}:".format(name), timeit(name + "('string')", setup='from __main__ import ' + name)) # We print the output so that we can check if the function is working as expected. - print(', '.join(map(function, strings)), '\n') \ No newline at end of file + print(', '.join(map(function, strings)), '\n')